Source.Library.Web.js.Alert
/**
* <p>Description: (Alert)</p>
* <p>@version 1.0.0</p>
* <p>Modifaction:(Date-Version-Author-Description)</p>
* <p>------------------------------------------------------------------------</p>
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
namespace Source.Library.Web.js
{
public class Alert
{
#region 使用HttpContext.Current.Response弹出对话框
/// <summary>
/// 网页消息对话框
/// </summary>
/// <param name="Message">要显示的消息文本</param>
public static void HttpContextAlert(string Message)
{
HttpContext.Current.Response.Write("<script language='javascript' type='text/javascript'>alert('" + Message + "')</script>");
HttpContext.Current.Response.Write("<script>history.go(-1)</script>");
HttpContext.Current.Response.End();
}
/// <summary>
/// 网页消息对话框
/// </summary>
/// <param name="Message">要显示的消息文本</param>
/// <param name="Src">点击确定后跳转的页面</param>
public static void HttpContextAlert(string Message, string Src)
{
HttpContext.Current.Response.Write("<script language='javascript' type='text/javascript'>alert('" + Message + "');location.href='" + Src + "'</script>");
HttpContext.Current.Response.End();
}
/// <summary>
/// 网页消息对话框
/// </summary>
/// <param name="Message">要显示的消息文本</param>
/// <param name="Close">关闭当前页面</param>
public static void HttpContextAlert(string Message, bool Close)
{
if (Close)
{
HttpContext.Current.Response.Write("<script language='javascript' type='text/javascript'>alert('" + Message + "');window.close()</script>");
HttpContext.Current.Response.End();
}
else
{
HttpContext.Current.Response.Write("<script language='javascript' type='text/javascript'>alert('" + Message + "')</script>");
HttpContext.Current.Response.Write("<script>history.go(-1)</script>");
HttpContext.Current.Response.End();
}
}
#endregion
#region 使用Page.RegisterClientScriptBlock弹出对话框
/// <summary>
/// 网页消息对话框
/// </summary>
/// <param name="page">弹出对话框的页面</param>
/// <param name="Message">要显示的消息文本</param>
public static void PageAlert(System.Web.UI.Page Page, string Message)
{
Message = Message.Replace("\\", "\\\\").Replace('\n'.ToString(), "\\n").Replace('\r'.ToString(), "\\r").Replace("'", "\\'").Replace("\"", "\\\""); // 去掉可能导致脚本错误的特殊字符
Page.RegisterClientScriptBlock("_AlertMessage", "<script language='javascript'>alert('" + Message + "');</script>");
}
/// <summary>
/// 网页消息对话框
/// </summary>
/// <param name="page">弹出对话框的页面</param>
/// <param name="Message">要显示的消息文本</param>
/// <param name="Src">点击确定后跳转的页面</param>
public static void PageAlert(System.Web.UI.Page Page, string Message, string Src)
{
Message = Message.Replace("\\", "\\\\").Replace('\n'.ToString(), "\\n").Replace('\r'.ToString(), "\\r").Replace("'", "\\'").Replace("\"", "\\\""); // 去掉可能导致脚本错误的特殊字符
Page.RegisterClientScriptBlock("_AlertMessage", "<script language='javascript'>alert('" + Message + "');location.href='" + Src + "'</script>");
}
/// <summary>
/// 网页消息对话框
/// </summary>
/// <param name="page">弹出对话框的页面</param>
/// <param name="Message">要显示的消息文本</param>
/// <param name="Close">关闭当前页面</param>
public static void PageAlert(System.Web.UI.Page Page, string Message, bool Close)
{
Message = Message.Replace("\\", "\\\\").Replace('\n'.ToString(), "\\n").Replace('\r'.ToString(), "\\r").Replace("'", "\\'").Replace("\"", "\\\""); // 去掉可能导致脚本错误的特殊字符
if (Close)
{
Page.RegisterClientScriptBlock("_AlertMessage", "<script language='javascript'>alert('" + Message + "');window.close()</script>");
}
else
{
Page.RegisterClientScriptBlock("_AlertMessage", "<script language='javascript'>alert('" + Message + "');</script>");
}
}
#endregion
#region 使用ScriptManager.RegisterClientScriptBlock弹出对话框
/// <summary>
/// 网页消息对话框
/// </summary>
/// <param name="Control">弹出对话框的控件</param>
/// <param name="Message">要显示的消息文本</param>
public static void ScriptManagerAlert(System.Web.UI.Control Control, string Message)
{
Message = Message.Replace("\\", "\\\\").Replace('\n'.ToString(), "\\n").Replace('\r'.ToString(), "\\r").Replace("'", "\\'").Replace("\"", "\\\""); // 去掉可能导致脚本错误的特殊字符
ScriptManager.RegisterClientScriptBlock(Control, Control.GetType(), "_AlertMessageWithControl", "alert('" + Message + "')", true);
}
/// <summary>
/// 网页消息对话框
/// </summary>
/// <param name="Control">弹出对话框的控件</param>
/// <param name="Message">要显示的消息文本</param>
/// <param name="Src">点击确定后跳转的页面</param>
public static void ScriptManagerAlert(System.Web.UI.Control Control, string Message,string Src)
{
Message = Message.Replace("\\", "\\\\").Replace('\n'.ToString(), "\\n").Replace('\r'.ToString(), "\\r").Replace("'", "\\'").Replace("\"", "\\\""); // 去掉可能导致脚本错误的特殊字符
ScriptManager.RegisterClientScriptBlock(Control, Control.GetType(), "_AlertMessageWithControl", "alert('" + Message + "');location.href='" + Src + "'", true);
}
/// <summary>
/// 网页消息对话框
/// </summary>
/// <param name="Control">弹出对话框的控件</param>
/// <param name="Message">要显示的消息文本</param>
/// <param name="Close">关闭当前页面</param>
public static void ScriptManagerAlert(System.Web.UI.Control Control, string Message, bool Close)
{
Message = Message.Replace("\\", "\\\\").Replace('\n'.ToString(), "\\n").Replace('\r'.ToString(), "\\r").Replace("'", "\\'").Replace("\"", "\\\""); // 去掉可能导致脚本错误的特殊字符
if (Close)
{
ScriptManager.RegisterClientScriptBlock(Control, Control.GetType(), "_AlertMessageWithControl", "alert('" + Message + "');window.close()", true);
}
else
{
ScriptManager.RegisterClientScriptBlock(Control, Control.GetType(), "_AlertMessageWithControl", "alert('" + Message + "')", true);
}
}
#endregion
}
}