Why does __VIEWSTATE hidden field gets rendered ev

2019-01-25 13:26发布

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?

2条回答
ゆ 、 Hurt°
2楼-- · 2019-01-25 13:37

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.

查看更多
闹够了就滚
3楼-- · 2019-01-25 13:43

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.

查看更多
登录 后发表回答