views:

980

answers:

2

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?

+7  A: 

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
This is correct, ViewState is also used to "authenticate" a PostBack to the page.
Rob Cooper
Yep, even if no control state is used the ViewState hidden field is rendered just for the sake of the IsPostBack property
korchev
A: 

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.