Pass session variable from page to page Asp.Net C#

In this article we have learn How to Pass session variable from page to page Asp.Net C#,when we need to store data throughout the project, then we can use session variable.

Asp.Net Session : 

Session is a State Management Technique. A Session can store the value on the Server. It can support any type of object to be stored along with our own custom objects. A session is one of the best techniques for State Management because it stores the data as client-based, in other words the data is stored for every user separately and the data is secured also because it is on the server.

Here i have explain how to use session variable in asp.net with example

Step 1 : Create Asp.Net C# project and add web form Login.aspx

protected void Page_Load(object sender, EventArgs e)
{

}

protected void Button1_Click(object sender, EventArgs e)
{
Session[“name”] = TextBox1.Text;
string abc = DateTime.Now.ToLongTimeString();
Session[“login_time”] = abc;
Response.Redirect(“home.aspx”);
}
}

Step 2 : Now Create Anothe Webform and give name home.aspx and add below code in page load

protected void Page_Load(object sender, EventArgs e)
{
string str = Session[“name”].ToString();
Label1.Text = “Wel Come:” + str;
Label2.Text = Session[“login_time”].ToString();
}

Step 3 : Run Project page Login.aspx, here we have pass Pass session variable during login form

Pass session variable from page to page Asp.Net C#Page home.aspx :

Pass session variable from page to page Asp.Net C#

SEE MORE