Stop a postback in javascript

32,044

Solution 1

How I do it; How I've done it:

<asp:LinkButton ID="linkKB" OnClientClick="absolutizeWidth(); return false;"  runat="server">Columns too small?</asp:LinkButton>

The "return false" stops the postback of the server control after the javascript function executes. Very useful.

Solution 2

To stop postback in javascript, write a "return false;" statement.

But i guess i just didn't understand your question or you asked it too unclear. :)

Solution 3

Are you trying to stop the post back after you refresh the page or after the Thickbox returns?

If you do not want to execute the postback when the user fires off an event, you can just return false within that even handler.

For example, the normal way to stop posting back during a page load is something like this:

onClick="if(SOMECONDITION != true) { return false; }" 

This will stop the postback being fired.

If a postback is already in progress and you want to try and abort it (which I think is what you are asking), you will need to "stop" the page from loading (as that's what the javascript is doing). Maybe try this:

IE: window.document.execCommand('Stop'); Other (Mozilla etc): window.stop();

I haven't tried this in a while (and it's off the top of my head), so the code may need some massaging.

If I've totally missed your question, I apologise, maybe you can clarify?

Solution 4

hmmm let me try.. (i dont speak english and dont know the correct words to explain that i want but ill try :P)

i call a javascript __doPostBack BUT it takes too much to respond and stay in Loading... i want to stop the postback, something like a response.end but in javascript.

if my script takes too much to execute then call a StopPostBack or something..

thanks.

Share:
32,044
NicoWheat
Author by

NicoWheat

Software programer (C#,VB.NET,PHP,Others+)

Updated on July 26, 2020

Comments

  • NicoWheat
    NicoWheat almost 4 years

    i have an ASP webform with a JQuery Thickbox, i have an image that opens the thickbox when user click.

    once open the thickbox it shows me a grid with several rows and a button to select one and after the user select the record it returns to the main page the recordselected and cause a __doPostBack()

    BUT! sometimes in IE6 it stay loading the postback and never ends i have to refresh the page and when it refresh it shows everything fine. but i dont want the postback stay loading AND it does not happend always.

    i have to call a __doPostBack because i need to find info related to the selected record.

    thanks.