Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. IE issue with canceling the onBeforeUnload function

IE issue with canceling the onBeforeUnload function

Scheduled Pinned Locked Moved ASP.NET
javascriptdata-structurestoolshelpquestion
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    ccrook
    wrote on last edited by
    #1

    I am having an issue with canceling an event I added to the window's onBeforeUnload event, when the browser is IE (7,8, &9). In FireFox my RegisterOnSubmitStatement is sufficient to set a flag to skip the warning, but in IE that code gets called after the onBeforeUnload. Here is the code in question:

    ScriptManager.RegisterStartupScript(page, typeof(Functions), "NavigateAway", @"
    window.SuppressExitWarning = false;

                window.onbeforeunload = confirmExit;
                function confirmExit(evt) {
                    var message = '" + JsEscape(message) + @"';
                    if (window.SuppressExitWarning == true) return;
    
                    if (typeof evt == 'undefined') evt = window.event;
                    if (evt) evt.returnValue = message;
                    return message;                
                };", true);            
             
                
            ScriptManager.RegisterOnSubmitStatement(page, typeof(Functions), "AllowNavigateAway", @"
                window.SuppressExitWarning = true;               
            ");
    

    If you add an alert to the "AllowNavigateAway" script, you can see the behaviour in IE -> The onBeforeUnload message pops up, then the alert. I have tried several ways to solve it, but they all have a flaw of some sort. A) Adding a setting of the global variable on the OnClientClick event to all possible form submitters will invariably miss something. That is to say, I do not have any idea of what controls will be on the page and even if I iterate through the control tree, I am likely to miss something that it not usually a control that submits but has it's AutoPostBack set to true. (e.g. DropDownList) B) Using jQuery to attach a method to the submit of the form is not an option because CKEditor has locked it up. C) Tracking the postback through a hidden input fails because it is not updated until after the onBeforeUnload. Any thoughts or ideas would be greatly appreciated.

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups