Search code examples
javascriptasp.netonclickanchorlinkbutton

Why doesn't this work in asp.net?


I used this,

<a title="Logout" onclick="javascript:document.getElementById('ctl00_ContentPlaceHolder1_LbLogout').click();" href="#" class="logout">Logout</a></li>
<asp:LinkButton ID="LbLogout" runat="server" style="display:none"
   onclick="LbLogout_Click">Sign out</asp:LinkButton>

The anchor tag doesn't seem to fire my linkbuttons onclick event...


Solution

  • Check if there is any javascript error. Also look at the page source and see if the id matches between your control and your javascript code. Try changing the control name to use UniqueID rather from the control rather than coded directly in case it has a different naming template hierarchy.

    <a title="Logout" onclick="javascript:document.getElementById('<%= Lblogout.UniqueID %>').click();" href="#" class="logout">Logout</a></li>