是的OnClientClick停止回传 [英] OnClientClick is stopping postback
问题描述
我有一组ASP.NET控件:
< ASP:LinkButton的ID =查找
的ClientIDMode =静态
=服务器
的CausesValidation =真
的OnClientClick =$('#查找)ATTR(禁用,禁用); $('#SearchingLabel)显示();>
<跨度>搜索< / SPAN>
< / ASP:LinkButton的>
< ASP:标签ID =SearchingLabel
的ClientIDMode =静态
=服务器
文本=搜索...
风格=显示:无; />
和,你可以看到,我消耗了的OnClientClick
,这样我可以禁用查找
按钮,显示在 SearchingLabel
(和JavaScript的没有错误BTW )。 pretty的基本的东西。
此外,围绕的CausesValidation
属性,我有页面上的验证控件,但目前没有验证错误。
不过,即使我没有返回假
从JavaScript的网页不回发。我甚至尝试返回true;
但这并没有改变任何东西(的不是真的令人惊奇,但它是值得一试的)<。 / P>
我期待着您的反馈!
好像要禁用的按钮,回发之前。
您可以尝试你的网页/脚本,而不禁用部分是:
的OnClientClick =$('#SearchingLabel)显示();。
如果这个作品,尝试用一个短暂的延迟:
的OnClientClick =的setTimeout(函数(){$('#查找)ATTR(禁用,禁用);},100); $('#SearchingLabel ')。显示();
I have a set of ASP.NET controls:
<asp:LinkButton ID="Find"
ClientIDMode="Static"
runat="server"
CausesValidation="true"
OnClientClick="$('#Find').attr('disabled', 'disabled'); $('#SearchingLabel').show();">
<span>Search</span>
</asp:LinkButton>
<asp:Label ID="SearchingLabel"
ClientIDMode="Static"
runat="server"
Text="Searching..."
style="display: none;" />
and as you can see I'm consuming the OnClientClick
so that I can disable the Find
button and show the SearchingLabel
(and the JavaScript works without error BTW). Pretty basic stuff.
Further, surrounding the CausesValidation
attribute, I do have validation controls on the page, but there are no current validation errors.
However, even though I'm not returning false
from the JavaScript the page isn't posting back. I've even attempted to return true;
but that didn't change anything (not really that surprising but it was worth a try).
I look forward to your feedback!
It seems like you are disabling your button, before the postback.
You could try your page/script without the disabling part in it:
OnClientClick="$('#SearchingLabel').show();"
If this works, try it with a short delay:
OnClientClick="setTimeout(function() { $('#Find').attr('disabled', 'disabled'); }, 100); $('#SearchingLabel').show();"
这篇关于是的OnClientClick停止回传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!