一个非常实用的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/archive/2012/03/03/2377944.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值