I've been trying to find the best way to handle this, this being alerting the user of an ASP.NET web form to the impending loss of data due to either:
-Changing forms via a link click, -Hitting "Back", -Closing the browser
I want a simple dialog to appear when they do so, giving them the option to change their minds. If they do, then the form remains. If they don't, carry on.
I've tried several jQuery plugins to handle this and am currently on dirty_form. It is properly trapping dirty forms and alerting me when I click a link or try to close the window (it doesn't handle back).
Unfortunately, handling the dirty form situation isn't enough as I cant seem to make it DO anything. My code:
<script type="text/javascript">
$(document).ready(function () {
$("#form2").dirty_form().dirty(function (event, data) {
/*what here */
});
});
</script>
How do I set this so that if they choose to go forward, it does and if they don't, it doesn't?
Also, how to I trap the browser "Back" function and handle it in the same way?