Monday, January 10, 2011

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.

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 Page object and server controls called ViewStateMode.ViewStateMode 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 the Page 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.

<%@ Page Language="C#"  ViewStateMode="Disabled" AutoEventWireup="true" 
 CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:Label ID="ViewStateDemoLebel1"  ViewStateMode="Enabled"  
 runat="server"></asp:Label>
     <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
    </div>
    </form>
</body>
</html>



No comments :

Post a Comment