How to minimize viewstate size of a page in asp.net?
Please help.
You have several options to reduce the ViewState:
-
Disable ViewState for controls that do not need it (this is the most effective solution). E.g. if you can cache some data on the server, then you can re-bind any databound controls with every request and it's not needed to save everything in ViewState.
-
Turn on HTTP compression on the server (IIS). This reduces the size of the page sent to the client, including the ViewState.
-
Compress the ViewState. This has an additional advantage over HTTP compression: it also reduces the size of PostBacks (data sent back to the server), since the ViewState is always sent back to the server during a PostBack. There are various approaches for this, e.g. as shown in this blog post.
-
Store the ViewState on the server instead of sending it in a hidden field with the page. The easiest way to do this is to use the SesionPageStatePersister, but there are other solutions which store the ViewState to disk instead of using the Session (see here for example).
Most of the points are highlighted within the other answers. Here's one that might be helpful:
Reduce the number of server controls (e.g. web/html controls) especiall those you do not need. Use simple HTML markups instead.
I've seen too many cases of redundant Table/Row/Cell Web Controls where normal < table >, < tr > and < td > will do.