Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Large ViewState value in ASP.NET

I am building an application in ASP.NET 2.0 and the value for the view state is huge:

<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTExNz...

The value contains 535,000 characters. Is this normal? How can I make it smaller?

like image 225
Jaelebi Avatar asked Jul 31 '09 07:07

Jaelebi


3 Answers

ViewState can grow ugly on you. Basically I would say that the problem is that ViewState is enabled by default on everything, and a lot of things don't need it to be. The most basic example would be Label objects.

Try disabling ViewState where you find it unnecessary (EnableViewState is the property you're looking for).

like image 31
Ostemar Avatar answered Oct 05 '22 09:10

Ostemar


Look into enabling ASP.NET tracing for your web pages - that will tell you what controls are storing how much in view state. You can then go and disable view state for controls that you know aren't using it.

like image 154
Justin Avatar answered Oct 05 '22 09:10

Justin


If you write a bit of code, you can store view state in your server instead of sending it through the network for a round trip. Also you can compress it to save space/bandwidth and load time.

Here is something I wrote about it some time back.

like image 25
Rakhitha Avatar answered Oct 05 '22 08:10

Rakhitha