今天本来是要在网上找一个东西,但一不小心就找到了一个想了好久的方法,很好用,希望对大家有所帮助:
说白了,就是写一个MessageBox类,然后在里面写一个静态方法就可以了:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
/// <summary>
/// MessageBox 的摘要说明
/// </summary>
public class MessageBox
{
public MessageBox()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public static void Show(System.Web.UI.Page page, string message)
{
string key = "message";
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append(" alert(' ");
sb.Append(message);
sb.Append(" ');window.location.reload();");
Type cstype = page.GetType();
ClientScriptManager cs = page.ClientScript;
if (!cs.IsStartupScriptRegistered(key))
{
cs.RegisterStartupScript(cstype, key, sb.ToString(), true);
}
}
}
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
/// <summary>
/// MessageBox 的摘要说明
/// </summary>
public class MessageBox
{
public MessageBox()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public static void Show(System.Web.UI.Page page, string message)
{
string key = "message";
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append(" alert(' ");
sb.Append(message);
sb.Append(" ');window.location.reload();");
Type cstype = page.GetType();
ClientScriptManager cs = page.ClientScript;
if (!cs.IsStartupScriptRegistered(key))
{
cs.RegisterStartupScript(cstype, key, sb.ToString(), true);
}
}
}