Guest User

Guest User

  • Tech Writer
  • 271
  • 36.4k

logout using link button in asp.net c#

Jul 29 2020 12:50 AM
i want when user click on logout its logout and it shows again Register and login option..
 
here is my code..
  1. <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">  
  2. <ul class="nav navbar-nav navbar-right">  
  3. <li><a href="#page-top" class="page-scroll">Home</a></li>  
  4. <li><a href="#about" class="page-scroll">About</a></li>  
  5. <li><a href="#contact" class="page-scroll">Contact</a></li>  
  6. <div class="dropdown">  
  7. <asp:LinkButton ID="lnkUserName" runat="server" Text="Register Her...!" OnCommand="lnkUserName_Command"></asp:LinkButton>  
  8. <div class="dropdown-content">  
  9. <asp:LinkButton ID="LinkButton1" runat="server" Text="Login...!" OnCommand="LinkButton1_Command"></asp:LinkButton>  
  10. </div>  
  11. </div>  
  12. </ul>  
  13. </div>  
  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. }  

Answers (7)