title: LinkButton inside LoginView LoggedInTemplate, how to trap the Click event?
body: <p>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.</p>
  
  <p>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.</p>
  
  <p>This is inside my Site.Master (and yes AutoEventWireup="true" is specified)</p>
  
  <pre><code>&lt;asp:LoginView ID="lgvLoginBox" runat="server"&gt;
      &lt;AnonymousTemplate&gt;
          &lt;asp:Login ID="lgLogin" runat="server" DisplayRememberMe="false" /&gt;                    
      &lt;/AnonymousTemplate&gt;
      &lt;LoggedInTemplate&gt;
          &lt;a href="../Account/ChangePassword.aspx"&gt;Change Password&lt;/a&gt;
          &lt;asp:LinkButton ID="lbLogoff" runat="server" Text="Log Out" OnClick="lbLogoff_Click"&gt;&lt;/asp:LinkButton&gt;                                                        
      &lt;/LoggedInTemplate&gt;
  &lt;/asp:LoginView&gt;   
  </code></pre>
  
  <p>This is inside my Site.Master.cs</p>
  
  <pre><code>protected void lbLogoff_Click(object sender, EventArgs e)
  {
      throw new NotImplementedException();
  }
  </code></pre>
  
  <p>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</p>
  
  <pre><code>LinkButton lbLogoff = lgvLoginBox.FindControl("lbLogoff") as LinkButton;
  if(lbLogoff != null)
      lbLogoff.Click +=new EventHandler(lbLogoff_Click);
  </code></pre>