1

I am working with asp.net MVC project. I do have partial views and rendering those view via AJAX call only, so I am not performing whole page refresh.

In one partial view user is making changes and calling another partial view without saving it.

So I want to force user with an alert to save changes before leaving edited partial view.

Is that possible using Javascript, jQuery or any other way?

I tried:

 window.onload = function () {
    window.addEventListener("beforeunload", function (e) {
            alert("was checked out, please check in back.");});
};

but its working on whole page refresh only. I am not refreshing whole page only partial page using AJAX.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Ravi Anand
  • 5,106
  • 9
  • 47
  • 77
  • Possible duplicate of [Is it possible to display a custom message in the beforeunload popup?](http://stackoverflow.com/questions/38879742/is-it-possible-to-display-a-custom-message-in-the-beforeunload-popup) – Dekel Oct 13 '16 at 11:33
  • Nope, beforeunload only fires when whole html page refreshed. – Ravi Anand Oct 13 '16 at 12:12
  • @RaviAnand : I know I may be a bit late, but did you find a solution to your problem ? I am facing the same problem in Angular JS application. – Mit Bhatt Apr 08 '18 at 03:56

0 Answers0