Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When to enable/disable Viewstate

I generaly disable viewstate for my ASP.net controls unless I explicitly know I am going to require view state for them. I have found that this can significantly reduce the page size of the HTML generated.

Is this good practice? When should be enabled or disabled?

like image 341
Jon P Avatar asked Sep 22 '08 06:09

Jon P


People also ask

What happens when ViewState is disabled?

If you disable ViewState, and a page needs it, the page will no longer work.

What is the use of Enable ViewState property?

View state enables a server control to maintain its state across HTTP requests. View state for a control is enabled if all of the following conditions are met: The EnableViewState property for the page is set to true . The EnableViewState property for the control is set to true .

Which property is used to disable enable ViewState of control at page level?

To disable view state for a page and to enable it for a specific control on the page, set the EnableViewState property of the page and the control to true , set the ViewStateMode property of the page to Disabled, and set the ViewStateMode property of the control to Enabled.

Does ViewState affect performance?

To accomplish our tasks, we use ViewState a lot, but as we know, it doesn't come free - it has a performance overhead. The ViewState is stored on the page in the form of a hidden variable. Its always advised to use the ViewState as little as possible. We also have other ways to reduce the performance overhead.


1 Answers

Yes it is a very good idea. One could argue that it should have been disabled by default by Microsoft, just like caching.

To see how bad Viewstate is in terms of size increased you can use a tool called Viewstate Analyzer. This is particularly useful when you have an existing application developed with Viewstate enabled.

Another good reason to disable Viewstate is that it is really hard to disable at a later stage, when you have loads of components depending on it.

like image 154
Sklivvz Avatar answered Sep 23 '22 23:09

Sklivvz