Skip to content Skip to sidebar Skip to footer

How To Capture When A User Is Leaving Asp.net Page Unexpectedly

I need to prompt a user when they are leaving my ASP.Net page unexpectedly with a message to ask if they are sure they want to leave. A post back or when the save button is clicked

Solution 1:

You can try using this:

$(window).unload(function(){
  alert('Message');
});

Solution 2:

In case people are interested this is the roundabout solution to my problem. How to tell if a page unload in ASP is a PostBack

Post a Comment for "How To Capture When A User Is Leaving Asp.net Page Unexpectedly"