Asp.Net How to Pass Session From One Page To Another Page

Asp.net Session how To pass Session One Page to another page

Introduction : 
This Artical Explain How to Pass user name and Login time From Login page To Home Page in asp.net
Step 1: Open Visual Studio and Create New Web Project
Step 2 : Add webform And give name Login.aspx  and pass user name& login Time as following
 
  namespace Web_Session
 {
    public partial class Login : System.Web.UI.Page
    {
        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 3 : Now Create Anothe Webform and give name home.aspx and add below code in page load 

 namespace Web_Session
{
    public partial class home : System.Web.UI.Page
    {
        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 4 : Run Project   page Login.aspx

 

Page home.aspx :


 




 
Previous
Next Post »