When to enable / disable ViewState

I generally turn off the viewstate for my ASP.net controls, unless I explicitly know that I will need view state for them. I found that this can significantly reduce the page size of the generated HTML.

Is this a good practice? When do I need to enable or disable?

+16
Sep 22 '08 at 6:35
source share
6 answers

Yes, that’s a very good idea. It can be argued that Microsoft should have been disabled by default, as was caching.

To find out how bad Viewstate is in terms of size, you can use the Viewstate Analyzer tool. This is especially useful if you have an existing application developed with ViewState enabled.

Another good reason to disable ViewState is that it’s actually difficult to disable it at a later stage, when you have many components depending on it.

+19
Sep 22 '08 at 6:57
source share

I think this is a good practice. Many ASP.NET developers are unaware that their view objects add huge baggage to the HTML that is sent to their users' browsers.

+5
Sep 22 '08 at 6:37
source share

This is a good practice. If you do not use ViewState values ​​in postbacks, or if they are needed by the most complex control, it is recommended that you save to ViewState as part of what will be sent to the client.

+4
Sep 22 '08 at 6:38
source share

You can find the information in the "ASP.NET Government Administration Guidelines" on MSDN to help you make your decision.

Generally, in ASP.NET 2.0 and later, disabling ViewState is less damaging due to the introduction of a control state to store information needed to raise events, etc.

+4
Sep 22 '08 at 7:06
source share

Definitely a good idea, it’s nothing worse than the page that the developer binds the DataGrid to Page_Load every time, but also sends a viewstate!

It is also a very good idea if you plan to use UpdatePanel from AJAX Extensions, it means that you send less during UpdatePanel request.

(Don’t cry to say that UpdatePanel can be good: P)

+2
Sep 22 '08 at 7:07
source share

_Viewstate may unnecessarily increase the number of bytes to be transmitted. Therefore, if the data will not be used next time, it is recommended to disable it.

0
Sep 22 '08 at 6:47
source share



All Articles