How do you implement ViewState for a control in ASP.Net 4.0?

 Posted by Tripati_tutu on 10/25/2010 | Category: ASP.NET Interview questions | Views: 4161 | Points: 40

In ASP.NET 4.0, Web server controls include a ViewStateMode property that lets you disable view state by default and then enable it only for the controls that require it in the page.

The ViewStateMode property takes an enumeration that has three values:
Enabled, Disabled, and Inherit.

Enabled enables view state for that control and for any child controls that are set to Inherit or that have nothing set.
Disabled disables view state, and
Inherit specifies that the control uses the ViewStateMode setting from the parent control.

 <asp:PlaceHolder ID="PlaceHolder1" runat="server" ViewStateMode="Disabled"> 

Disabled: <asp:Label ID="label1" runat="server" Text="[DeclaredValue]" /><br />
<asp:PlaceHolder ID="PlaceHolder2" runat="server" ViewStateMode="Enabled">
Enabled: <asp:Label ID="label2" runat="server" Text="[DeclaredValue]" />

Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response