I saw that __VIEWSTATE field gets rendered even though I have set the EnableViewState="false" at the page level. This field is not rendered if I remove runat="server" tag for the form element. Can somebody please explain this?
Asked
Active
Viewed 6,540 times
2 Answers
17
The __VIEWSTATE field is also used to store control state, which is not optional. Furthermore, the information contained in the view state is used to validate the postback, if I'm not mistaken (and validation is enabled, which is the default). So as long as you have the form with runat="server", you'll have a viewstate field. However, you should notice a much smaller field size if you disable all viewstate.

Chris
- 27,596
- 25
- 124
- 225
-
This is correct, ViewState is also used to "authenticate" a PostBack to the page. – Rob Cooper Nov 12 '08 at 06:22
-
2Yep, even if no control state is used the ViewState hidden field is rendered just for the sake of the IsPostBack property – Atanas Korchev Nov 13 '08 at 22:42
-
It is possible to have viewState have an empty value I posted the answer here: http://stackoverflow.com/questions/2432972/completely-remove-viewstate-for-specific-pages/5864040#5864040 – jimjim May 03 '11 at 01:22
0
Tip: In Asp.net, if you need to strip the __VIEWSTATE out entirely, override the Page.Render method, render the page into a string, and strip out the __VIEWSTATE text out of it.
-
3Thanks. This can also be done by removing `runat="server"` from the ` – Agnel Kurian Jul 22 '12 at 10:20