10.6. ViewState

ViewState is the mechanism by which ASP.NET stores the state of controls on a web form. This information is held in a hidden form value called __VIEWSTATE. Depending on the page's content, ViewState can get pretty large and is often unnecessary for controls that don't change such as labels.

ASP.NET 4.0 gives you the ability for controls to inherit ViewState settings from parent controls by using the new ViewStateMode property. This makes it easy to efficiently set ViewStateMode on a large number of controls.

ViewStateMode has three settings:

  • Enabled (ViewState used)

  • Disabled (ViewState not used)

  • Inherit (the ViewStateMode setting is inherited from the parent control)

The following example shows how to make lbl1 Label inherit pnlParent's ViewStateMode:

<asp:Panel ID="pnlParent" runat=server ViewStateMode=Disabled>
  <asp:Label ID="lbl1" Text="text" ViewStateMode=Inherit runat="server" />
</asp:Panel>

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.208.97