views:

690

answers:

5

Hi all,

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

A: 

Minimize View State size

Wael Dalloul
why down voted???
Wael Dalloul
The one who voted you down probably feel it's a google-copy+paste effort. You may want to elaborate more on the solution of the hyperlink you've provided.
o.k.w
that or it is because the link brings you down the page 2 posts past the one with any kind of meaningful content.
Aaron
+2  A: 

You cannot minimize the size of the ViewState. It's ASP.NET which serializes/deserializes. Though you could selectively disable ViewState for controls that don't need it.

Darin Dimitrov
You can compress it and save it in your own form field
grega g
A: 

You can turn on compression on the server to minimalize size of data transfered through the network or save viewState to disk and never send it to the client.

lama
+3  A: 

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).
M4N
+2  A: 

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.

o.k.w