View State How to use in asp.net

View State How to use in Asp.net

Introduction : This Tutorial Explain How to use View state in Asp.net. using the ViewState we can store some page or form data or information from the current page before the page is postback.  if we can not use the view state and page is postback the data or information of the page will be lost. thus it can be need to maintain view State in asp.net.

Here we are giving syntax of view state how to use in .net.

                ViewState["name"]=TextBox1.Text;
                ViewState["password"]=TextBox2.Text;

Here, ViewState["name"]  is store the TextBox1 data from the user enter  and  ViewState["password"TextBox2.Text data  when the page is postback or page data will lost then view state can be retrieve these data from it ViewState.

If  ViewState data is not null then we can retrieve these data using the following given Syntax 

      if (ViewState["name"] != null & ViewState["password"] != null)
            {
                TextBox1.Text = ViewState["name"].ToString();
                TextBox2.Text = ViewState["password"].ToString();
            }

Previous
Next Post »