开发者

warn before leaving the page using asp.net? [duplicate]

This question already has answers here: Best way to dete开发者_如何学Cct when a user leaves a web page? (10 answers) Closed 3 years ago.

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....)


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜