3

What is the best way to detect if a user leaves a web page without first saving?

I have searched before I posted this question, but I haven't found related topics to deal with ASP.NET (I have controls DropDownList, ListBox, TextBox....)

Andrew_CS
  • 2,542
  • 1
  • 18
  • 38
Nick Kahn
  • 19,652
  • 91
  • 275
  • 406

2 Answers2

1

I would use the JQuery serialize method to save off the form's state in the page's OnLoad event. Then serialize the page again in the OnBeforeUnload event. If the values are different, then the page has changed. You'll have to add a flag to know whether or not the page is unloading because the "Save" button is being clicked. If the values are different and the user didn't click "Save", then display the "Do you want to save before leaving?" box.

David
  • 34,223
  • 3
  • 62
  • 80
0

One very simple way is to do it the StackOverflow way:

http://www.jonstjohn.com/node/23

Basically it boils down to setting a method to be called in the onbeforeunload javascript event.

NotMe
  • 87,343
  • 27
  • 171
  • 245