Friday, January 16, 2009

Check for unsaved data and display a confirmation message if so

Below id the Link function and the necessary parameters that will make it work:

function ContractBasicsSave(){
    Form1.Command.value = "Save";
    isPostBack = true;
    Form1.submit();
}

var isPostBack = false;
var WarnDiscard = "<%=Proxy1.i18n.FM("WarnDiscardChanges")%>";
var WarnSave = "<%=Proxy1.i18n.FM("WarnSaveChanges")%>";
var WarnDelete = "<%=Proxy1.i18n.FM("WarnDelete")%>";
var ExcludeItems = {"SPANSIZE": "SPANSIZE", "GraphStatus": "GraphStatus" };
function checkChanges(url,cmdSave,cmdNoSave,noprompt) {
    if ((!isPostBack) && IsDirty(ExcludeItems) && (noprompt || confirm(WarnSave))) {
        Form1.action = url;
        
ContractBasicsSave();
        //NavLink(cmdSave, url);
    }
    else {
        //NavLink(cmdNoSave, url);
    }
}

Call the function from the Body OnUnload Event.
<body onunload="javascript:checkChanges('../zExelon/ContractBasics.asp', 'Save')">

Make sure you manage the isPostBack variable. Every time you do a Postback, you need to set it to true so the message does not fire off if you are doing a postback.

No comments:

Post a Comment