views:

18

answers:

0

I have a master page that contains a LoginView control. In the LoggedInTemplate I have a link button. I would like to trap that click event and do some cleanup (kill session, forms auth, etc). No matter what I do for some reason the button event never fires, and the LoginView switches back to the AnonymousTemplate.

The fact that the LoginView control switches to AnonymousTemplate bothers me, it seems that any control that causes a postback within the LoggedInTemplate the LoginView automatically assumes that it's time to switch back to the AnonymousTemplate. As a result I am speculating that the button that caused the postback to begin with is no longer rendered and the event that caused the postback never traps.

This is inside my Site.Master (and yes AutoEventWireup="true" is specified)

<asp:LoginView ID="lgvLoginBox" runat="server">
    <AnonymousTemplate>
        <asp:Login ID="lgLogin" runat="server" DisplayRememberMe="false" />                    
    </AnonymousTemplate>
    <LoggedInTemplate>
        <a href="../Account/ChangePassword.aspx">Change Password</a>
        <asp:LinkButton ID="lbLogoff" runat="server" Text="Log Out" OnClick="lbLogoff_Click"></asp:LinkButton>                                                        
    </LoggedInTemplate>
</asp:LoginView>   

This is inside my Site.Master.cs

protected void lbLogoff_Click(object sender, EventArgs e)
{
    throw new NotImplementedException();
}

I also attempted to register actual click event via Page_Init and Page_Load (in Site.Master.cs) with no luck. When the postback fires the control can no longer be found because the template on the LoginView is already anonymous

LinkButton lbLogoff = lgvLoginBox.FindControl("lbLogoff") as LinkButton;
if(lbLogoff != null)
    lbLogoff.Click +=new EventHandler(lbLogoff_Click);