Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to minimize viewstate size of a page in asp.net?

How to minimize viewstate size of a page in asp.net? Please help.

like image 872
Himadri Avatar asked Oct 10 '09 09:10

Himadri


Video Answer


2 Answers

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).
like image 89
M4N Avatar answered Nov 09 '22 11:11

M4N


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.

like image 29
o.k.w Avatar answered Nov 09 '22 10:11

o.k.w