Note that there are some explanatory texts on larger screens.

plurals
  1. POStop User Leaving Before Postback (Javascript/ASP.NET)
    primarykey
    data
    text
    <p>I have several functions running on a postback that can take a little time to complete.</p> <p>When postback is initiated I show a loading image with this code:</p> <pre><code>function showLoader() { document.getElementById("&lt;%=loadingImage.ClientID%&gt;").style.visibility="visible"; } </code></pre> <p>I want to be able to add code to this function so if user tries to leave at this point they are informed the operation is not complete.</p> <p>I found this code:</p> <pre><code>function goodbye(e) { if(!e) e = window.event; //e.cancelBubble is supported by IE - this will kill the bubbling process. e.cancelBubble = true; e.returnValue = 'You sure you want to leave?'; //This is displayed on the dialog //e.stopPropagation works in Firefox. if (e.stopPropagation) { e.stopPropagation(); e.preventDefault(); } } window.onbeforeunload=goodbye; </code></pre> <p>This works but I only want the code to be active when the loading image is active.</p> <p>I tried the following but it shows the alert message when the page eventually posts back:</p> <pre><code>function goodbye(e) { if(!e) e = window.event; //e.cancelBubble is supported by IE - this will kill the bubbling process. e.cancelBubble = true; e.returnValue = 'You sure you want to leave?'; //This is displayed on the dialog //e.stopPropagation works in Firefox. if (e.stopPropagation) { e.stopPropagation(); e.preventDefault(); } } function showLoader() { document.getElementById("&lt;%=loadingImage.ClientID%&gt;").style.visibility="visible"; window.onbeforeunload=goodbye; } </code></pre> <p>Any ideas how I can tweak this to just show when user leaves page and not when postback completes? </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload