Click here to Skip to main content
15,914,013 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

Currently i'm having page with different tabs.While i'm trying switch from one tab to another with any modifications.there is a promt to save and leave the page.But in one of the page.I have textbox and link button value of the text box is changed while clicking on link button(In click popup is opened and we have to select value).In this case the promt merssage is not showing.

Any help\Comments are highly appreciated.

Thanks in advance,
Balu
Posted

1 solution

You'll need using some client side scripting which does this check during the onbeforeunload event.
JavaScript
var showPrompt=true;
var isModified=false;
var hidePopup=false;

    function onBeforeUnload() {
        if (showPrompt) {
            if (isModified) {
                if (hidePopup || confirm("Click ok to save your changes or click cancel to discard your changes.")) {
                    doSave();
                }
            }
        }
        showPrompt = true;
        hidePopup = false;
    }

- showPrompt can be set to false when your clicking on an anchor tag which won't navigate you away from the page. For example
<a onclick="showPrompt=false" href="javascript:doX()" />

- isModified can be used to track when you need to save something. You could for example do something like
$("input").onchange(function(){isModified=true;});
To track undo's you might want to replace isModified with a function which checks the current state from the last saved state.

- hidePopup lets us force a save without confirming to the user.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900