10

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?

Blixt
  • 49,547
  • 13
  • 120
  • 153
Jaelebi
  • 5,879
  • 8
  • 32
  • 34

3 Answers3

11

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.

nhahtdh
  • 55,989
  • 15
  • 126
  • 162
Justin
  • 84,773
  • 49
  • 224
  • 367
  • Thanks for the tip. The problem was a dropdown list that was populated from a database. Dont know why it had a huge viewstate. – Jaelebi Jul 31 '09 at 08:12
  • I recommend the approach of programming without viewstate; enable and use only if required by the form and/or controls. In this case you might want to evaluate if viewstate is necessary for this particular control. If not sure, disable it at the control level, see what breaks, then re-enable it. Viewstate size may be multiples of the control's actual data size, so you should populate data sparingly - only include what's needed. – Matthew Aug 01 '09 at 23:26
6

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).

Ostemar
  • 5,778
  • 2
  • 19
  • 16
2

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.

Community
  • 1
  • 1
Rakhitha
  • 328
  • 2
  • 11