Sep 11, 2012

ViewState Control in ASP.NET 4.0


Viewstate is one of the most important and useful client side state management mechanisms. It can store the page value at the time of post back (Sending and Receiving information from Server) of your page. ASP.NET pages provide the View State property as a built-in structure for automatically storing values between multiple requests for the same page.
We generally use “EnableViewState” Properties for both Page Level and Server Control Level to maintain the view state. Till ASP.NET 3.5 Version, Page Level view state control treat as highest priorities. Which means If we setEnableViewState= “False” in page level, that will automatically be derived by all the server side controls. In that case, if we set “EnableViewState=”True”” for any server side control will treat it as false, as we have defined them “False” in Page Level. Here is one complete article on ASP.NET 2.0/3.5 View State, which may be helpful for you.
Now, let’s have a look into the changes in ViewState Control in ASP.NET 4.0. There is a massive change in View State Control in ASP.NET 4.0 which is very much helpful for the developer also. ASP.NET 4.0 added a new property to Pageobject and server controls called ViewStateModeViewStateMode properties has 3 values:
  1. Enabled: This value will enable the view state for page level or control level. This is the default value for thePage object.
  2. Disabled: This value will disable the viewstate for both page level and control level.
  3. Inherit: This value will make the control inherit the setting of the parent. This is the default value for the server control.
These properties and their behaviors indicate the server control viewstates are totally independents on Page Level View State. Which means, ViewStateMode=”Disabled” will disable the viewstate for all the controls for those pages by default, but if we explicitly specify the page level control viewstatemode= ”Enabled”, then only that control viewstate will be maintained during the postback. Let’s check few scenarios of ViewStateMode in ASP.NET 4.0.

No comments:

Post a Comment