Click here to Skip to main content
15,566,305 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I would like to display as Welcome and logged in username in my web application.
Posted
Comments
Maciej Los 11-Apr-14 3:07am    
What have you done till now? Where are you stuck?

Nothing to do more....Just assign the username textbox value to the Session variable in the login page and access that Session variable to the master page:

Login page:

C#
   DataTable dt = Check username in the database and put in a datatable
   if (dt != null && dt.Rows.Count > 0)
 {
      Session["UserName"] = txtUserName.Text.Trim();

      Response.Redirect("/Home.aspx");

}
   else
   {
        lblMsg.Text = "username or password invalid";
   }


In the master page:

C#
if (Session["UserName"] != null)
                    lblWelcome.Text = "Welcome " + Session["UserName"].ToString();
                else
                    lblWelcome.Text = "Welcome Guest"
 
Share this answer
 
v2
Please read my comment to the question.

I'd suggest to start here: How to: Pass Values Between ASP.NET Web Pages[^] + passing Session variables from ContentPage to MasterPage's Control[^].
 
Share this answer
 
 
Share this answer
 
Comments
Member 10476757 11-Apr-14 3:20am    
might to useful by using session variable to store the values and retrieve where ever needed
This is the example in which we can store session value in the master page lable control...

Label lb = this.Master.FindControl("LblTitle") as Label;
lb.Text = Session["Categoryid"];
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900