Home > DeveloperSection > Blogs > EnableViewState in ASP.NET

EnableViewState in ASP.NET


ASP.Net ASP.Net 
Ratings:
0 Comment(s)
 2203  View(s)
Rate this:

EnableViewState in ASP.NET

In this blog, I’m explaining the concept of enableviewstate in asp.net.

EnableViewState or ViewStateMode is the property allows automatic state management feature enables server control to repopulate without writing any extra code. This feature is not free however, since the state of a control is passed to and from the server in a hidden form field. You should be aware of when ViewState is helping you and when it is not.

Example

Step 1

Write the code in EnableViewState.aspx:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="EnableViewState.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title></title>

    <style type="text/css">

        th {

            text-align:left;

        }

        </style>

</head>

<body>

    <form id="form1" runat="server">

    <div>

        <asp:Label ID="lblControl1" runat="server" EnableViewState="false"></asp:Label>

        <br />

             <asp:Label ID="lblControl2" runat="server" EnableViewState="true"></asp:Label>

        <br />

         <asp:Button ID="btnCheck" runat="server" Text="Check"  style="height: 26px" />

        <br />

        <br />

       

     <asp:Label ID="lblMsg" runat="server" EnableViewState="true" Text="Before Post Back"></asp:Label>

    </div>

    </form>

</body>

</html>

Step 2

Run the application:

Step 3

After click on Check button:

In this example one label control disable EnableViewState and another label enable EnableViewState.


Don't want to miss updates? Please click the below button!

Follow MindStick