ViewState In ASP.NET Web Forms | State Management In ASP.NET | ASP.NET WebForms

 using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;


namespace View_State

{

    public partial class WebForm1 : System.Web.UI.Page

    {

        string a,b;

        protected void Page_Load(object sender, EventArgs e)

        {


        }


        protected void RestoreButton_Click(object sender, EventArgs e)

        {

            if (ViewState["user"] != null)

            {

                UserTextBox.Text = ViewState["user"].ToString();

            }

            if (ViewState["pass"] != null)

            {

                PassTextBox.Text = ViewState["pass"].ToString();

            }

        }


        protected void SubmitButton_Click(object sender, EventArgs e)

        {

            ViewState["user"] = UserTextBox.Text;

            ViewState["pass"] = PassTextBox.Text;


            UserTextBox.Text = string.Empty;

            PassTextBox.Text = string.Empty;


            Response.Redirect("WebForm2.aspx");

        }

    }

}

Above File is View_State\WebForm1.aspx.cs





using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;


namespace View_State

{

    public partial class WebForm2 : System.Web.UI.Page

    {

        protected void Page_Load(object sender, EventArgs e)

        {


        }


        protected void Button1_Click(object sender, EventArgs e)

        {

            if (ViewState["user"] != null)

            {

                TextBox1.Text = ViewState["user"].ToString();

            }

            if (ViewState["pass"] != null)

            {

                TextBox2.Text = ViewState["pass"].ToString();

            }

        }

    }

}

Above File is View_State\WebForm2.aspx.cs








Comments

Popular posts from this blog

AJAX Method Of jQuery AJAX In ASP.NET Web Forms | Learn ASP.NET Web Forms

List Box In ASP.NET Web Forms | ASP.NET ListBox | Web Forms Tutorial | ASP.NET

Display Auto Increment Value In Text Field After Insert To Database ASP.NET