prevent的LinkButton回发的OnClientClick不工作。为什么? [英] 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.
我需要prevent一个链接按钮回发及以下code不工作。在code肯定是被打在所有需要的地方。
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.
链接按钮定义:
<asp:LinkButton ID="NavHelp" OnClientClick="showConfirm(event);" OnClick="NavHelp_Click" ToolTip="Help" runat="server"></asp:LinkButton>
JavaScript函数(肯定被击中)
Javascript function (definitely being hit)
function showConfirm(event) {
event.stopPropagation();
return false;
}
但后 showConfirm
返回false链接按钮还是回发到服务器端 NavHelp
方法。
However after showConfirm
returns false the link button still posts back to the server side NavHelp
method.
作为一个方面说明,我也把由.NET生成的 __ doPostback
方法中设置断点,它并在 showConfirm $遭到袭击C $ C>返回false。
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?
推荐答案
右键,理解了它。我需要包括在的OnClientClick属性return语句:
Right, figured it out. I needed to include the return statement in the OnClientClick attribute:
OnClientClick="return showConfirm(event);"
不是
OnClientClick="showConfirm(event);"
这篇关于prevent的LinkButton回发的OnClientClick不工作。为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!