Skip to content
Loading
logout using link button in asp.net c#
  1. protected void Page_Load(object sender, EventArgs e)  
  2. {  
  3. if(Session["UserName"]!=null)  
  4. {  
  5. string query = "select * from User where UserName'" + Session["UserName"] + "'";  
  6. lnkUserName.Text = string.Format("Welcome {0}", Session["UserName"].ToString());  
  7. LinkButton1.Text = string.Format("Logout");  
  8. lnkUserName.PostBackUrl = "Profile.aspx";  
  9. }  
  10. }  
  11. protected void lnkUserName_Command(object sender, CommandEventArgs e)  
  12. {  
  13. Response.Redirect("/SignIn.aspx");  
  14. }  
  15. protected void LinkButton1_Command(object sender, CommandEventArgs e)  
  16. {  
  17. if (LinkButton1.Text == "Logout")  
  18. {  
  19. Session["UserName"] = "";  
  20. Response.Redirect("/Walpaper.aspx");  
  21. }  
  22. else  
  23. {  
  24. Response.Redirect("/Login.aspx");  
  25. }  

7 Replies

Know the answer? Post it — somebody with the same question will find it here.