Tutorial :When to enable/disable Viewstate



Question:

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:1

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.


Solution:2

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.


Solution:3

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.


Solution:4

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.


Solution:5

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)


Solution:6

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


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »