views:

404

answers:

2

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?

+4  A: 

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

Marpe
Would it depend on objects per page or in the entire application?
Jaelebi
It would depend on the objects in that page.
SharePoint Newbie
Might be worth adding an example: `<asp:Label ID="productName" EnableViewState="false" Text="[Product Name]" runat="server" />`
Blixt
+3  A: 

Look into enabling Asp.Net tracing (http://www.asp101.com/articles/robert/tracing/default.asp) for your web pages - that will tell you what controls are storing how much in viewstate. You can then go and disable viewstare for controls that you know aren't using it.

Kragen
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
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.
Matt