views:

36

answers:

2

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...

+2  A: 

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>
Fadrian Sudaman
A: 

In addition to the naming issue:

  • you must return false from a link onclick handler, otherwise the # link will be followed, cancelling any navigation that might occur from the other link click (and scrolling the page to the top);

  • don't use javascript: prefixes in event handlers attributes. They don't do anything. You're thinking of javascript: pseudo-URLs. Which should never be used anyway;

  • you can't activate a link's default action (of navigating the page) by calling click() on it. All click() will do is execute any onclick JS action associated with it. If you want to navigate the page you will have to do it manually by setting location.href= link.href;

  • don't use a link for something with an active effect, like logout. It should be a normal form-like button. You can always use CSS to style it so it looks like a link.

bobince