Mike Perrenoud
Mike Perrenoud

Reputation: 67898

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!

Upvotes: 4

Views: 2732

Answers (2)

Adem Ey&#252;boğlu
Adem Ey&#252;boğlu

Reputation: 19

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) {
   .......
}

Upvotes: 0

Jacco
Jacco

Reputation: 3272

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();"

Upvotes: 8

Related Questions