Revision: 51023
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at September 13, 2011 00:55 by Krummelz
Initial Code
function setConfirmUnload(on) { window.onbeforeunload = (on) ? unloadMessage : null; } function unloadMessage() { return 'You have entered new data on this page. If you navigate away from this page without first saving your data, the changes will be lost.'; }
Initial URL
Initial Description
Easy to use in C# ASP.NET: to prevent a user from losing data when navigating away from whatever page they are on, just add string setConfirmUnload = "setConfirmUnload(true);"; ScriptManager.RegisterStartupScript(this, this.GetType(), "", setConfirmUnload, true); to you code somewhere, or just call setConfirmUnload(true); from the onClick or onClientClick even of a link. To allow a link to navigate away, pass in false instead. Might be handy on an ASP.NET master page.
Initial Title
Javascript to warn the user that they will lose data if they go away from this page
Initial Tags
Initial Language
JavaScript