Search code examples
asp.netweb-user-controls

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?


Solution

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