Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OnClientClick is stopping postback

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!

like image 559
Mike Perrenoud Avatar asked Feb 17 '23 23:02

Mike Perrenoud


1 Answers

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();"
like image 129
Jacco Avatar answered Feb 28 '23 04:02

Jacco