📄 confirmationpage.cs
字号:
//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
// Copyright (c) Telligent Systems Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
using System;
using System.IO;
using System.Text.RegularExpressions;
using System.Web.UI;
namespace CommunityServer.Components
{
/// <summary>
/// Summary description for ConfirmationPage.
/// </summary>
public class ConfirmationPage : Page
{
public ConfirmationPage()
{
//
// TODO: Add constructor logic here
//
}
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 = "<script language=\"javascript\">g_blnCheckUnload = true;function RunOnBeforeUnload() {if (g_blnCheckUnload) {window.event.returnValue = '";
const 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(),"<body","<body onbeforeunload=\"RunOnBeforeUnload()\"",RegexOptions.IgnoreCase));
}
else
{
base.Render(writer);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -