C# .NET - link button in masterpage not getting fired

Asked By abinav shankar on 30-Jan-12 12:12 AM

Hi

I have a master page in which there is link button called logout when I click this it has to take me to the login page but the event is not getting fired how to do it pl tell me any other alternative

smr replied to abinav shankar on 30-Jan-12 12:23 AM
hi

Add the below code in the page_load of your target page( xxx.aspx):

If (Not (Page.PreviousPage) Is Nothing) Then
  Dim lb As LinkButton = CType(Me.Master.FindControl("LinkButton1"),LinkButton)
  lb.CssClass = "menuSelected"
End If

follow
http://forums.asp.net/p/1056830/1506055.aspx
http://forums.asp.net/t/1634841.aspx
Sreekumar P replied to abinav shankar on 30-Jan-12 12:27 AM
Hi,

1. First check for any Javscript errors ... ? (reply me with the errors).
2. Using Updatepanel ?
3. Maybe you can share your code here, otherwise it's difficult to investigate the problem

Riley K replied to abinav shankar on 30-Jan-12 12:33 AM


IF that is a server control place a break point and check first


protected void LinkButton1_Click(object sender, EventArgs e)
{
    Session["UserName"] = null;
    Session.Abandon();
    Response.Clear();
    Response.Redirect("HomePage.aspx");
}
D Company replied to abinav shankar on 30-Jan-12 12:34 AM
hello friend.

do in this way,
In the Page_Load event for the logout.aspx page, enter the following code:

Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1)); 
Response.Cache.SetCacheability(HttpCacheability.NoCache); 
Response.Cache.SetNoStore();
 

and on click of log out link . put this code


string redirectUrl = FormsAuthentication.LoginUrl + "?ReturnUrl=login.aspx"; 
FormsAuthentication.SignOut(); 
Response.Redirect(redirectUrl); 



let me know if it  is not working for you!!
Regards
D
Chintan Vaghela replied to abinav shankar on 30-Jan-12 12:35 AM

Hello,

public void LoginLink_OnClick(object sender, EventArgs args)
{
  FormsAuthentication.SignOut();
  FormsAuthentication.RedirectToLoginPage();
}
 
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
 
<form id="form1" runat="server">
Welcome <b><%=User.Identity.Name%></b>. Not <b><%=User.Identity.Name%></b>? 
Click <asp:LinkButton id="LoginLink" Text="here" 
            OnClick="LoginLink_OnClick" runat="server" />
to sign in.
 
<!-- Page Contents -->
 
</form>
 
 
 
</body>
</html>

 

 

Hope this is helpful !

Thanks

 

 

 

 

 

Jitendra Faye replied to abinav shankar on 30-Jan-12 01:17 AM

Only one thing to check-


have to bound link event of link button like this-


<asp:LinkButton ID="LinkButton1" runat="server" onclick="LinkButton1_Click">LinkButton</asp:LinkButton>


in code behind-


protected void LinkButton1_Click(object sender, EventArgs e)
{
 Session["USERNAME"] = null;
 Response.Redirect("login.aspx");
}

Try this adnd let me know.

kalpana aparnathi replied to abinav shankar on 30-Jan-12 01:14 PM
hi,

LinkButton lb = (LinkButton)this.Master.FindControl("LinkButton1");
lb.CssClass = "menuSelected";