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

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.

Step 1

Write the code in EnableViewState.aspx:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="EnableViewState.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html>
<html xmlns="">
<head runat="server">
    <style type="text/css">
        th {
    <form id="form1" runat="server">
        <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>

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.

  Modified On Sep-18-2014 01:24:25 PM

Leave Comment