Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent LinkButton post back OnClientClick not working. Why?

I know there are plenty of answers surrounding this topic but I just cannot get this to work.

I need to prevent a link button posting back and the following code is not working. The code is definitely being hit in all the required places.

Link button definition:

  <asp:LinkButton ID="NavHelp" OnClientClick="showConfirm(event);" OnClick="NavHelp_Click" ToolTip="Help" runat="server"></asp:LinkButton>

Javascript function (definitely being hit)

function showConfirm(event) {
  event.stopPropagation();
  return false;
}

However after showConfirm returns false the link button still posts back to the server side NavHelp method.

As a side note, I also put a breakpoint in the __doPostback method generated by .NET and it does get hit after showConfirm returns false.

Can anyone shed any light on this?

like image 543
Dan Cook Avatar asked May 23 '13 09:05

Dan Cook


1 Answers

Right, figured it out. I needed to include the return statement in the OnClientClick attribute:

OnClientClick="return showConfirm(event);"

NOT

OnClientClick="showConfirm(event);"
like image 134
Dan Cook Avatar answered Oct 28 '22 22:10

Dan Cook