开发者

Showing the alert on moving through one page to another by Unsave Change

Scenario:

I have a CaseEdit.aspx page in which on have 3 buttons:

  • AddImage
  • FinalPage
  • QuestionAns

and one web user controls that CaseContentList.ascx.

In casecontentlist I have datalist in that I am lbtnDisplay.

When we are clicking on caseEdit.aspx btn we are adding the name to the lbtnDisplay (suppose I clicked on btn addimage then addimage will add to dataliast, if btnqusans clicked then qusans will add in that datalist lbtn).

Now, on every btn click I am opening the following web user controls:

  • on AddImage click i am opening AddImage.ascx (using tinymce editor)

  • on FinalPage click i am opening FinalPage.ascx (using tinymce editor)

  • on QuestionAns click i am opening QuestionAns.ascx (using tinymce editor)

  • and when i am clicking on datalist link btn (lbtnDisplay) on any item then, PageContent.ascx is opening.

All these things are happening on caseEdit.aspx page.

开发者_Go百科

Requirement:

  1. when we are in edit mode of any page and moving to some other page it must show the confirmation alert box.

  2. when page content is opened on lbtnDisplay click and then we are going to some other page it should not show the confirmation alert box.


You could add additional variable that you check before redirecting user to the page:

var allowRedirect = false;

function FinalFunction() 
{ 
    if (!allowRedirect)
    {
        return confirm("Are you sure you have saved your changes?"); 
    }
} 

By default allowRedirect s set to false, so all trise to change the page would show confirmation box.

Then, you could set allowRedirect to true, when user clicks lbtnDisplay button:

document.getElementById.onlick = function(){ allowRedirect = true; };

Didn't test my code, but it gives you the concept how it could be done.


I have taken a hidden field and keeping the value=0, when i am clicking on edit button changing the value to 1 and after that i am comparing the value of text box and hidden filed when user click on some other link its working fine..

function ValueChanged() {
     var textvalue;

     textvalue = removeHTMLTags(tinyMCE.get('<%=txbText.ClientID %>').getContent());
     if (textvalue != tinyText) {
         var ssave = window.confirm('Your changes are not saved. Do you want to save your changes before you exit.')
         if (ssave == true) {
             document.getElementById('<%=btnSave.ClientID%>').click();
             return false;
         }
         else
             return true;
         }
     }      
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜