View State

ViewState

  • View State of a webform is available only with in that webform
  • View State is stored on the page in a hidden field called _ViewState. Because of this, the    View State will be lost, if you navigate away from the page, or if the browser is closed.
  • ViewState is used by all asp.net controls to retain their state across post-back
Example:-

view_state.aspx :-


<div align="center">
        <asp:Label ID="Label1" runat="server" Text=""></asp:Label>
        <br />
        <asp:Button ID="Submit" runat="server" Text="Button" OnClick="Submit_Click" />
 
    </div>

view_state.aspx.cs :-


 int count = 0;
 
    protected void Submit_Click(object sender, EventArgs e)
    {
        if (ViewState["abc"] != null)
        {
            count = (int)ViewState["abc"];
        }
        count++;
        Label1.Text += "you are clicked :-" + count + "times<br/>";
        ViewState["abc"] = count;
    }

No comments:

Post a Comment

Xamarin Android Project App

Xamarin Android Project App 1. Xamarin -- Make a CALCULATOR Android App   https://drive.google.com/open?id=0B8OPCXLrtKPmWC1FWWtFM2lraVk...