how to use session in

Posted by Ankitsrist under ASP.NET category on | Points: 40 | Views : 2732
lets see how to deal with session, in your login page button click event handler write the following code

//assign textbox(username) value to session, Loginname is just a session name you can give any name to it
Session["Loginname"] = TextBox1.Text;

and if u have master page, take one label and one button(for logout, login functionality) and then write the following code in page load section
protected void Page_Load(object sender, EventArgs e)
if (Session["Loginname"]!= null)
//if session is not null then display the name of the user
Label1.Text = "Welcome : " + Session["Loginname"];
Button1.Text = "logout";

Label1.Text = "Welcome: Guest!";
Button1.Text = "login here";


Comments or Responses

Login to post response