Fog Creek Software
Discussion Board




Welcome! and rules

Joel on Software

large viewstate when using checkbox in datagrid

hi,everyone!

i test a simple datagrid,which have only a template column within it a checkbox control,perhaps bound to 50 rows data.

-the page level enableviewstate=false;
-the datagird level  enableviewstate=false;
-the checkbox control level  enableviewstate=false;

---however,there still appears a large viewstate!!!

why?any suggestion?or a fixed bug in asp.net 2.0?

thanks.

wens_yao
Wednesday, January 26, 2005

To find out why, you can enable ASP.NET tracing (<trace> element in your web.config file).  The trace output will tell you the contribution of each control on the page to the total viewstate size.

There also exist utilities to decode ViewState (google for "decode ViewState") which can also help to understand what you're putting in ViewState.

Joe
Wednesday, January 26, 2005

You can use a viewstate decoder to find out what's in there.  And you can stress out about how to get some things out of it.

Or you can just keep the ViewState somewhere else.  I just went through an exercise to get ViewState compression / offloading to filesystem.

I'm much happier now.  Some of my pages are 25% smaller.

Good References:
http://www.mostlylucid.co.uk/archive/2004/01/03/694.aspx
http://msdn.microsoft.com/asp.net/default.aspx?pull=/library/en-us/dnaspp/html/viewstate.asp#viewstate_topic8

You can roll your own solution pretty quickly using the above resources, but if you'd prefer to buy, these guys offer commercial components to solve the problem:
http://www.flesk.net/fleskviewstate.aspx 75 Euros
http://www.ms-inc.net/aspnet.aspx?ProductID=ViewStateManager $10 US - but something seems to be wrong with their website.

Michael Mchenry
Wednesday, January 26, 2005

> Or you can just keep the ViewState somewhere else.

Storing ViewState on the server is something worth considering, but it's not a panacea.  In some cases the disadvantages may outweigh the benefits: e.g. need to store in a server resource that is accessible to all servers in a web farm; need to store ViewState data on the server for a long time as a client may return to your site long after the first request (e.g. he may view a page from a client-side cache, then post back to your server days or weeks after the original request).

I've found that ViewState bloat is rarely a problem if you design your pages carefully, and monitor your use of ViewState using the ASP.NET trace facility.

Joe
Thursday, January 27, 2005

*  Recent Topics

*  Fog Creek Home