一个非常实用的C#弹出对话框类(包括弹出对话框,跳转到指定页面,关闭窗口)

using System; 
using System.Web.UI;
using System.Collections.Generic;
using System.Text;
using System.Web;

namespace Web.Comman.Utility
{
/// <summary>
/// 弹出提示框
/// </summary>
public class ShowMessageInfo
{
/// <summary>
/// 静态方法,实现提示信息,并跳转到相应的网页
/// </summary>
/// <param name="Msg">提示信息</param>
/// <param name="GoToUrl">跳转到相应的网页的url</param>
public static void ShowMessage(string Msg, string GoToUrl)
{
Page p = (Page)System.Web.HttpContext.Current.Handler;
ClientScriptManager CSM = p.ClientScript;
String ScriptName = "ShowMsgToUrl";
String ScriptMsg = "alert('" + Msg + "');window.open('" + GoToUrl + "','_self')";
Type CsType = p.GetType();
if (!CSM.IsStartupScriptRegistered(CsType, ScriptName))
{
CSM.RegisterStartupScript(CsType, ScriptName, ScriptMsg, true);
}
}
/// <summary>
/// 静态方法,仅实现提示信息。
/// </summary>
/// <param name="Msg">错误信息提示</param>
public static void JustShowMsg(string Msg)
{
Page p = (Page)System.Web.HttpContext.Current.Handler;
ClientScriptManager CSM = p.ClientScript;
String ScriptName = "JustShowMsg";
String ScriptMsg = "alert('" + Msg + "');";
Type CsType = p.GetType();
if (!CSM.IsStartupScriptRegistered(CsType, ScriptName))
{
CSM.RegisterStartupScript(CsType, ScriptName, ScriptMsg, true);
}
}
/// <summary>
/// 跳转到指定的url
/// </summary>
/// <param name="url">需要跳转的url地址</param>
public static void GotoUrl(string url)
{
Page p = (Page)System.Web.HttpContext.Current.Handler;
ClientScriptManager CSM = p.ClientScript;
String ScriptName = "ToUrl";
String ScriptMsg = "top.location.href='" + url + "'";
Type CsType = p.GetType();
CSM.RegisterStartupScript(CsType, ScriptName, ScriptMsg, true);
}
/// <summary>
/// 先提示信息,然后关闭窗口
/// </summary>
/// <param name="Msg"></param>
public static void ShowMsgThenCloseWindow(String Msg)
{
Page p = (Page)System.Web.HttpContext.Current.Handler;
ClientScriptManager CSM = p.ClientScript;
String ScriptName = "close";
String ScriptMsg = "alert('" + Msg + "');window.opener = null;window.open('','_self');window.close();";
Type CsType = p.GetType();
if (!CSM.IsStartupScriptRegistered(CsType, ScriptName))
{
CSM.RegisterStartupScript(CsType, ScriptName, ScriptMsg, true);
}
}
/// <summary>
/// 关闭窗口
/// </summary>
public static void CloseWindow()
{
Page p = (Page)System.Web.HttpContext.Current.Handler;
ClientScriptManager CSM = p.ClientScript;
String ScriptName = "close";
String ScriptMsg = "window.opener = null;window.open('','_self');window.close();";
Type CsType = p.GetType();
}
}
}
原文地址:https://www.cnblogs.com/jason009/p/2377944.html