Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
180
rated 0 times [  184] [ 4]  / answers: 1 / hits: 23261  / 11 Years ago, thu, may 23, 2013, 12:00:00

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?


More From » asp.net

 Answers
41

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



OnClientClick=return showConfirm(event);


NOT



OnClientClick=showConfirm(event);

[#78066] Wednesday, May 22, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
cruzs

Total Points: 710
Total Questions: 113
Total Answers: 100

Location: Nepal
Member since Sat, Jul 18, 2020
4 Years ago
cruzs questions
Thu, Nov 26, 20, 00:00, 4 Years ago
Wed, Oct 28, 20, 00:00, 4 Years ago
Wed, Aug 19, 20, 00:00, 4 Years ago
Sun, Aug 2, 20, 00:00, 4 Years ago
;