how to use ViewState in asp.net

asp.net ViewState example: how to use ViewState in asp.net 

aspx :
 
<body>
    <form id="form1" runat="server">
    <div>
   
    </div>
    <asp:Label ID="lblCount" runat="server" Text=""></asp:Label>
    <br />
    <br />
    <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
    </form>
</body>

 
 c# :

 protected void Button1_Click(object sender, EventArgs e)
        {
            int count = 1;
            if (ViewState["count"] == null)
            {
                count = 1;
            }
            else
            {
                count = (int)ViewState["count"] + 1;
            }
            ViewState["count"] = count;
            lblCount.Text = "Count = " + count;
        }




 

Comments

Popular posts from this blog

Add Serial no in crystal report without coding

File operations in C# (.net)

SQL – Generate decimal numbers sequence for particular number range