/ Published in: JavaScript

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.
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.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
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.'; }
Comments
