views:

984

answers:

6

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?

+4  A: 

I think it's good practice. Many ASP.NET devs are unaware that their viewstates add tremendous baggage to the HTML that's being sent to their users' browsers.

cruizer
+4  A: 

It's a good practice. Unless you use ViewState values on postbacks, or they are required by some complex control itself it's good idea to save on ViewState as part of what will be sent to the client.

dimarzionist
A: 

_Viewstate can unnecessarily increase the number of bytes that need to be transferred. So unless the data is going to be used the next time , it's a good idea to switch it off.

+10  A: 

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.

Sklivvz
+3  A: 

You may find the information contained in the "ASP.NET State Management Recommendations" article on MSDN useful for making your decision.

Generally in ASP.NET 2.0 and above disabling the ViewState is less destructive due to the introduction of the Control State for storing informaton required for raising events etc.

Aydsman
+2  A: 

Definately a good idea, nothing worse that a page which a developer is binding a dataGrid in the Page_Load every time but also submitting the viewstate!

It's also a really good idea if you are planning on using the UpdatePanel from the AJAX Extensions, it means you're submitting less during the UpdatePanel request.

(Don't flame for saying that an UpdatePanel can be good :P)

Slace