admin管理员组文章数量:1397074
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!
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!
Share Improve this question edited Jan 7, 2013 at 12:30 Mike Perrenoud asked Jan 7, 2013 at 12:23 Mike PerrenoudMike Perrenoud 68k32 gold badges166 silver badges238 bronze badges 3-
The
CausesValidation="true"
? Do you have ValidationControls on your page? Those could cause it – codingbiz Commented Jan 7, 2013 at 12:26 - @codingbiz, I do have validation controls on the page, but there are no validation errors. – Mike Perrenoud Commented Jan 7, 2013 at 12:29
-
This can also occur if you remove the control or the parent control of the control that you are posting back with, something like
OnClientClick="$(this).remove()"
will cause the same issue. – David Rogers Commented Jun 2, 2016 at 14:05
2 Answers
Reset to default 8It 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();"
Try this js code onload
Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequest);
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequest);
function BeginRequest(sender, e) {
e.get_postBackElement().disabled = true;
// or your code
}
function EndRequest(sender, e) {
.......
}
本文标签: cOnClientClick is stopping postbackStack Overflow
版权声明:本文标题:c# - OnClientClick is stopping postback - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744678536a2619259.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论