Skip to content Skip to sidebar Skip to footer

How To Avoid The “are You Sure You Want To Navigate Away From This Page?” When Changes Committed? On Pagination Click Of Gridview In Ie

My web page contains grid-view with many input fields.I want to give alert to user before moving to next tab. My script is working fine in Mozilla Firefox and chrome but in IE the

Solution 1:

just set the the value to null on pagination click

window.onbeforeunload = null;

UPDATE 1

try this one instead of your code:

var myEvent = window.attachEvent || window.addEventListener;
    var chkevent = window.attachEvent ? 'onbeforeunload' : 'beforeunload'; /// make IE7, IE8 compitablemyEvent(chkevent, function (e) { // For >=IE7, Chrome, Firefoxvar confirmationMessage = 'Are you sure to leave the page?';  // a space
        (e || window.event).returnValue = confirmationMessage;
        return confirmationMessage;
    });

UPDATE 2

after you use window.onbeforeunload = null; in your pagination control to rebind the alert in your update panel try this solution, it may help you with that issue:

   $(document).ready(function () {
     bindPageAlert();
   });

    functionbindPageAlert()
    {
        var myEvent = window.attachEvent || window.addEventListener;
        var chkevent = window.attachEvent ? 'onbeforeunload' : 'beforeunload';
        myEvent(chkevent, function (e) { // For >=IE7, Chrome, Firefoxvar confirmationMessage = 'Are you sure to leave the page?';  // a space
            (e || window.event).returnValue = confirmationMessage;
            return confirmationMessage;
        });
    }

    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(bindPageAlert);

Post a Comment for "How To Avoid The “are You Sure You Want To Navigate Away From This Page?” When Changes Committed? On Pagination Click Of Gridview In Ie"