Confirmation Page
**_ _ **
**_ 1. _ ** **_ Introduction _ **
In New or Edit page, users might press the Close button by mistake and lost the content that they have input. To avoid this mistaken action, application should prompt users before the page is closed. This page will not be closed unless users confirm that.
This document gives the implementation details for how the Confirmation Page works. It can be used in:
? New Page
? Edit Page
? Any other pages need confirmation before close
**_ 2. _ ** **_ Solution _ **
** 2.1 ConfirmationPage Class **
ConfirmationPage class is available in the root of XXXWeb project. This is a class derived from PageBase.
This class implements the function of “cause the user to confirm navigating away from the current page”.
using System;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Web.UI;
namespace Proloq.ProloqWeb
{
///
1<summary>
2/// Will cause the user to confirm navigating away from the current page. This behavior can be overriden.
3/// </summary>
public class ConfirmationPage : Proloq.ProloqWeb.PageBase
{
public ConfirmationPage()
{
}
private bool _IsInEdit = false;
public bool IsInEdit
{
get {return this._IsInEdit;}
set {this._IsInEdit = value;}
}
private string _message = "You will lose any non-saved text";
public string Message
{
get{return _message;}
set{_message = value;}
}
protected override void OnPreRender(EventArgs e)
{
//If we are in edit mode, register the script
if(IsInEdit)
{
Page.RegisterClientScriptBlock("ConfirmationBeforeLeaving",string.Format("{0}{1}{2}",scriptStart,Message,scriptEnd));
}
base.OnPreRender (e);
}
const string scriptStart = "
1<script language='\"javascript\"'>g_blnCheckUnload = true;function RunOnBeforeUnload() {if (g_blnCheckUnload) {window.event.returnValue = '";
2const string scriptEnd = "'; } } function bypassCheck() { g_blnCheckUnload = false; }</script>
";
public static readonly string ByPassFuncationName = "bypassCheck()";
protected override void Render(HtmlTextWriter writer)
{
//If we are in edit mode, wire up the onbeforeunload event
if(IsInEdit)
{
TextWriter tempWriter = new StringWriter();
base.Render(new HtmlTextWriter(tempWriter));
writer.Write(Regex.Replace(tempWriter.ToString(),"
1<body","<body **="" ---="" .aspx="" .page;="" .savebutton.attributes.add("onclick",confirmationpage.bypassfuncationname);="" 2.2="" 2.2.1="" 2.2.2="" 2.2.3="" :="" ;="" <="" a="" add="" and="" are="" at="" base.render(writer);="" bellow="" border="0" button="" buttons="" cancel="" class="" class.="" code="" codeback="" codebehind="" codebehind:="" confirmation.="" confirmationpage="" confirmpage="(ConfirmationPage)" confirmpage.isinedit="true" confirmpage.message="You will lose any unsaved content" derived="" do="" e)="" edit="" else="" example:="" file="" following="" for="" from="" function="" function:="" going="" here.="" if="" img="" implement="" in="" inheritance="" is="" issue="" like="" not="" object="" onbeforeunload='\"RunOnBeforeUnload()\"",RegexOptions.IgnoreCase));' onclick="javascript:bypassCheck();GoBack();" other="" page="" page_load(="" pageload,="" pages="" private="" product="" product_edit="" public="" put="" run="" savebutton="" sender,="" server,="" setconfirmation()="" setconfirmation();="" should="" some="" src=" ```
2 =Image1URLBase
3``` /btn_cancel_g.gif" style="CURSOR: hand" system.eventargs="" take="" the="" them.="" there="" this="" to="" use="" void="" want="" which="" you="" {="" }="" …="">
4
5---
6
7bypassCheck() function is to clear the confirmation for the page.</body","<body>