ASP.net viewstate problems and thoughts

I did a benchmark of my project aspx pages that are written in asp.net 1.1 and observe some improvements in viewstate and overall page size.

Before Change of Code,
ReportMapping_Selection.aspx has page size of 39 kb
has viewstate size of 16 kb

After Change of Code,
ReportMapping_Selection.aspx has page size of 33 kb
has viewstate size of 12 kb


Before Change of Code,
AddReportMapping_Selection.aspx has page size of 53 kb
has viewstate size of 43 kb

After Change of Code,
AddReportMapping_Selection.aspx has page size of 17 kb
has viewstate size of 4 kb

I did use a free tool though called ViewStateHelper.

Forumula  - >  Page Size = ViewState + HTML markup

Viewstate can be reduced by using html controls to an extent but it is not a full-proof solution.

Scenario 1:
For example, datagrid in asp.net don't have an equivalent client-side control. Imagine a datagrid with 1,600 rows of data on 1 single page. Yes, I can probably improve the viewstate by disabling the viewstate row by row but however due to the large amount of data, HTML markup remains big.

According to the above forumla, if I have a small viewstate but big HTML markup size, I still  stuck with a big page like 4 megs? That is where pagination comes in. Lol.

Scenario 2:
If I use viewstate to store my datatable on a page, and with each click of a button, it refresh the datatable, it will result in viewstate being different at different points of the day. That is where Caching comes in.

By looking at Scenario 1 and 2, you will notice both are common Viewstate problems but have varying solutions. So there is no hard and fast way to reduce a page size but rather you use the tool you are blessed with to solve a problem at hand depending on Scenarios.


Published Wednesday, June 25, 2008 4:48 PM by darenhan

Comments

# re: ASP.net viewstate problems and thoughts

Thursday, June 26, 2008 7:48 AM by cruizer

in general, ViewState is what I hate about ASP.NET Web Forms. hopefully the MVC framework matures real soon now (RSN) :)

# re: ASP.net viewstate problems and thoughts

Tuesday, July 01, 2008 5:30 PM by icelava

If you want to be adventurous and challenged with a programming exercise, you can write paging at the database layer and implement your own paging controls at the UI layer.

http://msdn.microsoft.com/en-us/magazine/cc163854.aspx#S3

ASP.NET Forums and Community Server achieve paging using this method.

Powered by Community Server (Commercial Edition), by Telligent Systems