常用JavaScript代碼提示公共類封裝
2024-09-06 12:41:22
供稿:網(wǎng)友
希望對大家有幫助!
代碼如下:
using System;
using System.Web;
namespace Jake.PublicJS
{
/// <summary>
/// Summary description for PublicJS
/// </summary>
public class PublicJS
{
public PublicJS()
{
//
// TODO: Add constructor logic here
//
}
/// <summary>
/// 1.靜態(tài)方法,彈出信息窗體
/// </summary>
/// <param name="page">頁面對象</param>
/// <param name="description">信息內(nèi)容</param>
/// <example>
/// PublicJS.Alert(this,"NiHao!");
/// </example>
public static void Alert(System.Web.UI.Page page, string description)
{
if (description != null)
{
string scriptString = "<script language=JavaScript><!--
";
scriptString += "alert('" + description + "');";
scriptString += "
// --></script>";
if (!page.IsClientScriptBlockRegistered("clientScript"))
page.RegisterClientScriptBlock("clientScript", scriptString);
}
else
{
Alert(page, "描述信息為空!");
}
}
/// <summary>
/// 2.靜態(tài)方法,彈出信息窗體,并刷新頁面
/// </summary>
/// <param name="page">頁面對象</param>
/// <param name="description">信息內(nèi)容</param>
/// <example>
/// PublicJS.Alert(this,"NiHao!");
/// </example>
public static void ReLoadMessage(System.Web.UI.Page page, string description, string PageID)
{
if (description != null)
{
string scriptString = "<script language=JavaScript><!--
";
scriptString += "alert('" + description + "');";
scriptString += "parent." + PageID + ".location.reload()";
scriptString += "
// --></script>";
if (!page.IsClientScriptBlockRegistered("clientScript"))
page.RegisterClientScriptBlock("clientScript", scriptString);
}
else
{
Alert(page, "描述信息為空!");
}
}
public static void Redirect(string url)
{
HttpResponse Response;
Response = HttpContext.Current.Response;
Response.Write("<script language=JScript><!--
/n");
Response.Write("window.location='" + url + "';/n");
Response.Write("
// --></script>/n");
}
/// <summary>
/// 彈出對話框,轉(zhuǎn)向所指頁面
/// </summary>
/// <param name="description">提示信息</param>
/// <param name="url">頁面</param>
public static void MsgBoxRedrict(string description, string url)
{
HttpResponse Response;
Response = HttpContext.Current.Response;
Response.Write("<script language=JScript><!--
/n");
Response.Write("alert('" + description + "');/n");
Response.Write("window.location='" + url + "';/n");
Response.Write("
// --></script>/n");
//Response.Redirect(url);
}
/// <summary>
/// 彈出對話框,確實轉(zhuǎn)向所指頁面