Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ViewStateMode Disabled but still getting ViewState element

I have a ASP.NET 4.0 webforms site where I have the MasterPage so it is set to ViewStateMode="Disabled" along with the content placeholders being set similarly.

When I'd view my page I'd still see a ViewState field rendered, I then tried adding the ViewStateMode="Disabled" to the page level also but that didn't change anything.

like image 798
Chris Marisic Avatar asked May 14 '10 12:05

Chris Marisic


People also ask

How do I get rid of ViewState?

To disable ViewState for a page To disable ViewState for a single page, set the EnableViewState attribute in the @ Page directive to false, as in the following: <%@ Page Language="C#" EnableViewState="false" AutoEventWireup="true" CodeFile="URLRouting. aspx.

What happens when ViewState is disabled?

If you disable ViewState, and a page needs it, the page will no longer work.

Is ViewState shared between controls?

Since each control is responsible for its own viewstate, and stores required data in it, so it can render/postback etc, it ends up that there is a lage duplication in the viewstate, since the Person control stores all the data, and then each child control stores its own data again.

What is the use of Enable ViewState property?

View state enables a server control to maintain its state across HTTP requests. View state for a control is enabled if all of the following conditions are met: The EnableViewState property for the page is set to true . The EnableViewState property for the control is set to true .


1 Answers

I'm not aware of latest changes on ViewState for the framework 4 but you have to take into account that the ViewState field rendered to the client has 2 components: ViewState itself and ControlState.

The ControlState is ALWAYS sent to the client on the viewstate field no matter if you have enabled ViewState or not.

So you can expect to drastically reduce the size of the viewstate field sent to the client but not completely remove it.

Control state contains the minimal things that a control needs to persist across postbacks in order to work as expected.

Control State

In addition to view state, ASP.NET supports control state. The page uses control state to persist control information that must be retained between postbacks, even if view state is disabled for the page or for a control. Like view state, control state is stored in one or more hidden fields.

http://msdn.microsoft.com/en-us/library/bb386448.aspx

like image 129
Claudio Redi Avatar answered Sep 22 '22 10:09

Claudio Redi