常用JavaScript代碼提示公共類封裝
更新時間:2009年08月02日 13:00:38 作者:
常用JavaScript代碼提示公共類整理封裝,可直接用于項目開發(fā),
作為開發(fā)常用代碼,還是有一定使用價值的,呵呵
希望對大家有幫助!
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">信息內容</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">信息內容</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>
/// 彈出對話框,轉向所指頁面
/// </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>
/// 彈出對話框,確實轉向所指頁面
/// </summary>
/// <param name="description">提示信息</param>
/// <param name="url">頁面</param>
/// <param name="PrintUrl">確定后轉向的頁面</param>
public static void MsgBoxRedrict(string description, string url, string PrintUrl)
{
HttpResponse Response;
Response = HttpContext.Current.Response;
Response.Write("<script language=JScript><!--
\n");
Response.Write("function prints()\n");
Response.Write("{\n if(confirm('" + description + "'))\n");
Response.Write("{window.location='" + PrintUrl + "';}\n");
Response.Write("else\n");
Response.Write("{window.location='" + url + "';}\n}\n");
Response.Write("prints();\n");
Response.Write("
// --></script>\n");
}
/// <summary>
/// 彈出對話框,轉向所指頁面
/// </summary>
/// <param name="description">提示信息</param>
public static void MsgBoxRedrict(string description)
{
HttpResponse Response;
Response = HttpContext.Current.Response;
Response.Write("<script language=JScript><!--
\n");
Response.Write("alert('" + description + "');\n");
Response.Write("history.go(-1);\n");
Response.Write("
// --></script>\n");
}
/// <summary>
///2 靜態(tài)方法,關閉一個網(wǎng)頁的父窗口,例如一個frame關閉其父窗口。
/// </summary>
/// <param name="page">頁面對象</param>
/// <example>
/// PublicJS.CloseParent(this);
/// </example>
public static void CloseParent(System.Web.UI.Page page)
{
string scriptString = "<script language=JavaScript><!--
";
scriptString += "window.parent.close();";
scriptString += "
// --></script>";
if (!page.IsClientScriptBlockRegistered("clientScript"))
page.RegisterClientScriptBlock("clientScript", scriptString);
}
/// <summary>
///2 靜態(tài)方法,關閉一個網(wǎng)頁窗口。
/// </summary>
/// <param name="page">頁面對象</param>
/// <example>
/// PublicJS.CloseParent(this);
/// </example>
public static void ClosePage(System.Web.UI.Page page)
{
string scriptString = "<script language=JavaScript><!--
";
scriptString += "window.close();";
scriptString += "
// --></script>";
if (!page.IsClientScriptBlockRegistered("clientScript"))
page.RegisterClientScriptBlock("clientScript", scriptString);
}
/// <summary>
///3 靜態(tài)方法,輸出一則消息后關閉一個模態(tài)網(wǎng)頁窗口并刷新父窗口
/// 前提條件是必須調用此類中的OpenModalDialog方法
/// 在該方法中自動生成刷新方法才能實現(xiàn)父頁面刷新。
/// </summary>
/// <param name="page">頁面對象</param>
/// <param name="page">輸出消息</param>
/// <example>
/// PublicJS.CloseModalDialog(this);
/// </example>
public static void CloseModalDialogMessage(System.Web.UI.Page page, string Message)
{
string scriptString = "<script language=JavaScript><!--
";
scriptString += "alert('" + Message + "');";
scriptString += "window.close();";
scriptString += "
// --></script>";
if (!page.IsClientScriptBlockRegistered("clientScript"))
page.RegisterClientScriptBlock("clientScript", scriptString);
}
/// <summary>
///3 靜態(tài)方法,關閉一個模態(tài)網(wǎng)頁窗口并刷新父窗口
/// 前提條件是必須調用此類中的OpenModalDialog方法
/// 在該方法中自動生成刷新方法才能實現(xiàn)父頁面刷新。
/// </summary>
/// <param name="page">頁面對象</param>
/// <example>
/// PublicJS.CloseModalDialog(this);
/// </example>
public static void CloseModalDialog(System.Web.UI.Page page)
{
string scriptString = "<script language=JavaScript><!--
";
scriptString += "window.close();";
scriptString += "
// --></script>";
if (!page.IsClientScriptBlockRegistered("clientScript"))
page.RegisterClientScriptBlock("clientScript", scriptString);
}
/// <summary>
/// 關閉模態(tài)網(wǎng)頁并傳值到父頁面
/// </summary>
/// <param name="page">頁面對象</param>
/// <param name="strValue">需要傳遞的值</param>
public static void CloseModalDialog(System.Web.UI.Page page, string strValue)
{
string scriptString = "<script language=JavaScript><!--
";
scriptString += "window.returnValue='" + strValue.Trim() + "';";
scriptString += "window.close();";
scriptString += "
// --></script>";
if (!page.IsClientScriptBlockRegistered("clientScript"))
page.RegisterClientScriptBlock("clientScript", scriptString);
}
/// <summary>
///4 靜態(tài)方法,關閉一個網(wǎng)頁窗口。
/// </summary>
/// <param name="page">頁面對象</param>
/// <example>
/// PublicJS.CloseWindow(this);
/// </example>
public static void CloseWindow(System.Web.UI.Page page)
{
string scriptString = "<script language=JavaScript><!--
";
scriptString += "window.opener=null;";
scriptString += "window.close();";
scriptString += "
// --></script>";
if (!page.IsClientScriptBlockRegistered("clientScript"))
page.RegisterClientScriptBlock("clientScript", scriptString);
}
/// <summary>
///5 靜態(tài)方法,執(zhí)行客戶端一小塊腳本語言,
///利用page的RegisterClientScriptBlock方法在客戶端注冊一段腳本,
///參數(shù)script無需包括html標記<script type="text/javascript"><!--
、
// --></script>。
/// </summary>
/// <param name="page">頁面對象</param>
/// <param name="script">javascript腳本</param>
/// <example>
/// PublicJS.ExecuteBlock(this,"alert("Hello");");
/// </example>
public static void ExecuteBlock(System.Web.UI.Page page, string script)
{
if (script != null)
{
string scriptString = "<script language=JavaScript><!--
";
scriptString += script;
scriptString += "
// --></script>";
if (!page.IsClientScriptBlockRegistered("clientScript9"))
page.RegisterClientScriptBlock("clientScript9", scriptString);
}
else
{
Alert(page, "JavaScript腳本不能為空!");
}
}
/// <summary>
///6 靜態(tài)方法,打開一個網(wǎng)頁對話框,并生成刷新頁面方法。
/// </summary>
/// <param name="page">頁面對象</param>
/// <param name="URL">頁面名稱</param>
/// <param name="Width">寬度</param>
/// <param name="Height">高度</param>
/// <example>
/// PublicJS.OpenModalDialog(page,"weihu.aspx",700,350);
/// </example>
public static void OpenModalDialog(System.Web.UI.Page page, string URL, int Width, int Height)
{
if (URL != null)
{
if (Width == 0 || Height == 0)
{
Alert(page, "頁面寬度和高度不能為零!");
return;
}
string scriptString = "<script language='javascript'><!--
";
scriptString += "function Refreshs()";
scriptString += "{";
//scriptString += "window.location.href= window.location.href;";
scriptString += "}";
scriptString += "window.showModalDialog('" + URL + "',window,'dialogHeight:" + Height + "px;dialogWidth:" + Width + "px;center:Yes;help:No;scroll:auto;resizable:No;status:No;');";
scriptString += "window.location.href= window.location.href;";
scriptString += "
// --></script>";
if (!page.IsStartupScriptRegistered("Startup"))
page.RegisterStartupScript("Startup", scriptString);
}
else
{
Alert(page, "頁面地址不能為空!");
}
}
/// <summary>
///7 靜態(tài)方法,打開一個模式對話框
/// </summary>
/// <param name="page">頁面對象</param>
/// <param name="URL">頁面名稱</param>
/// <param name="Attribute">屬性</param>
/// <param name="Width">寬度</param>
/// <param name="Height">高度</param>
/// <example>
/// PublicJS.OpenModalDialog(page,"weihu.aspx","scrollbars=yes,status=yes",700,350);
/// </example>
public static void OpenModalDialog(System.Web.UI.Page page, string URL, string Attribute, int Width, int Height)
{
if (URL != null)
{
if (Width == 0 || Height == 0)
{
Alert(page, "頁面寬度和高度不能為零!");
return;
}
if (Attribute == "")
Attribute = "center:Yes;help:No;scroll:No;resizable:No;status:No;";
string scriptString = "<script language='javascript'><!--
";
//scriptString += "function Refresh()";
//scriptString += "{";
scriptString += "window.showModalDialog('" + URL + "',window,'dialogHeight:" + Height + "px;dialogWidth:" + Width + "px;" + Attribute + "')";
//scriptString += " window.location.href= window.location.href;";
//scriptString += "}";
//scriptString += " Refresh();";
scriptString += "
// --></script>";
if (!page.IsStartupScriptRegistered("Startup"))
page.RegisterStartupScript("Startup", scriptString);
}
else
{
Alert(page, "頁面地址不能為空!");
}
}
/// <summary>
///8 靜態(tài)方法,打開一個無模式網(wǎng)頁對話框。
/// </summary>
/// <param name="page">頁面對象</param>
/// <param name="URL">頁面名稱</param>
/// <param name="Width">寬度</param>
/// <param name="Height">高度</param>
/// <example>
/// PublicJS.OpenDialog(page,"weihu.aspx",700,350);
/// </example>
public static void OpenDialog(System.Web.UI.Page page, string URL, int Width, int Height)
{
if (URL != null)
{
if (Width == 0 || Height == 0)
{
Alert(page, "頁面寬度和高度不能為零!");
return;
}
string str = "<script language='javascript'><!--
"
+ "window.open('" + URL + "','','location=no,status=no,menubar=no,scrollbars=auto,resizable=Yes,width=" + Width + ",height=" + Height + "')"
+ "
// --></script>";
if (!page.IsClientScriptBlockRegistered("clientScript"))
page.RegisterClientScriptBlock("clientScript", str);
}
else
{
Alert(page, "頁面地址不能為空!");
}
}
/// <summary>
///9 靜態(tài)方法,打開一個IE窗口(無標題欄、工具欄、地址欄等)。
/// </summary>
/// <param name="page">頁面對象</param>
/// <param name="URL">頁面名稱</param>
/// <param name="Width">寬度</param>
/// <param name="Height">高度</param>
/// <param name="Left">左邊距</param>
/// <param name="Top">上邊距</param>
/// <example>
/// PublicJS.OpenIEWindow(page,"weihu.aspx",700,350,10,20);
/// </example>
public static void OpenIEWindow(System.Web.UI.Page page, string URL, int Width, int Height, int Left, int Top)
{
if (URL != null)
{
if (Width == 0 || Height == 0)
{
Alert(page, "頁面寬度和高度不能為零!");
return;
}
string str = "<script language='javascript'><!--
"
+ "tt = window.open('" + URL + "','','location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=" + Width + ",height=" + Height + ",left=" + Left + ",top=" + Top + "'); tt.focus();"
+ "
// --></script>";
if (!page.IsClientScriptBlockRegistered("clientScript"))
page.RegisterClientScriptBlock("clientScript", str);
}
else
{
Alert(page, "頁面地址不能為空!");
}
}
/// <summary>
///9 靜態(tài)方法,打開一個IE窗口(無標題欄、工具欄、地址欄等)。
/// </summary>
/// <param name="page">頁面對象</param>
/// <param name="URL">頁面名稱</param>
/// <param name="Width">寬度</param>
/// <param name="Height">高度</param>
/// <param name="Left">左邊距</param>
/// <param name="Top">上邊距</param>
/// <example>
/// PublicJS.OpenIEWindow(page,"weihu.aspx",700,350,10,20);
/// </example>
public static void OpenIEWindows(System.Web.UI.Page page, string URL, int Width, int Height, int Left, int Top)
{
if (URL != null)
{
if (Width == 0 || Height == 0)
{
Alert(page, "頁面寬度和高度不能為零!");
return;
}
//string str = "<script language='javascript'><!--
"
// + "window.open('" + URL + "','','location=no,status=no,menubar=yes,scrollbars=yes,resizable=no,width=" + Width + ",height=" + Height + ",left=" + Left + ",top=" + Top + "');"
// + "
// --></script>";
string str = "<script language='javascript'><!--
"
+ "tt = window.open('" + URL + "','','location=no,status=no,toolbar=no,menubar=yes,scrollbars=yes,resizable=yes,fullscreen=no'); tt.focus();"
+ "
// --></script>";
if (!page.IsClientScriptBlockRegistered("clientScript"))
page.RegisterClientScriptBlock("clientScript", str);
}
else
{
Alert(page, "頁面地址不能為空!");
}
}
public static void OpenIEWindows(System.Web.UI.Page page, string URL, int Width, int Height)
{
if (URL != null)
{
if (Width == 0 || Height == 0)
{
Alert(page, "頁面寬度和高度不能為零!");
return;
}
string str = "<script language='javascript'><!--
";
str += "a = window.open(\"" + URL + "\", \"\", \"fullscreen=0,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1,width=" + Width + ",height=" + Height + "\", true);";
str += "a.focus();";
str += "
// --></script>";
if (!page.IsClientScriptBlockRegistered("clientScript"))
page.RegisterClientScriptBlock("clientScript", str);
}
else
{
Alert(page, "頁面地址不能為空!");
}
}
/// <summary>
///10 靜態(tài)方法,打開一個IE窗口(無標題欄、工具欄、地址欄等)。
/// </summary>
/// <param name="page">頁面對象</param>
/// <param name="URL">頁面名稱</param>
/// <example>
/// PublicJS.OpenIEWindow(page,"weihu.aspx");
/// </example>
public static void OpenIEWindow(System.Web.UI.Page page, string URL)
{
if (URL != null)
{
string str = "<script language='javascript'><!--
"
+ "var Cwin=window.open('" + URL + "','','location=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=screen.availWidth-20,height=screen.availHeight-20,left=10,top=10');"
+ "Cwin.resizeTo(screen.availWidth-20,screen.availHeight-20);"
+ "
// --></script>";
if (!page.IsClientScriptBlockRegistered("clientScript"))
page.RegisterClientScriptBlock("clientScript", str);
}
else
{
Alert(page, "頁面地址不能為空!");
}
}
/// <summary>
///11 靜態(tài)方法,打開一個IE窗口(無標題欄、工具欄、地址欄等)。
/// </summary>
/// <param name="page">頁面對象</param>
/// <param name="URL">頁面名稱</param>
/// <param name="Width">寬度</param>
/// <param name="Height">高度</param>
/// <example>
/// PublicJS.OpenIEWindow(page,"weihu.aspx",700,350);
/// </example>
public static void OpenIEWindow(System.Web.UI.Page page, string URL, int Width, int Height)
{
if (URL != null)
{
string str = "<script language='javascript'><!--
"
+ "var Cwin=window.open('" + URL + "','','location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=" + Width + ",height=" + Height + ",left=10,top=10');"
+ "Cwin.moveTo((screen.availWidth-" + Width + ")/2,(screen.availHeight-" + Height + ")/2);"
+ "
// --></script>";
if (!page.IsClientScriptBlockRegistered("clientScript"))
page.RegisterClientScriptBlock("clientScript", str);
}
else
{
Alert(page, "頁面地址不能為空!");
}
}
/// <summary>
///12 靜態(tài)方法,打開一個IE窗口(無標題欄、工具欄、地址欄等)
///在屏幕的最右邊,上下滿屏,寬度由參數(shù)指定。
/// </summary>
/// <param name="page">頁面對象</param>
/// <param name="URL">頁面名稱</param>
/// <param name="Width">寬度</param>
/// <example>
/// PublicJS.OpenIEWindowRight(page,"weihu.aspx",700);
/// </example>
public static void OpenIEWindowRight(System.Web.UI.Page page, string URL, int Width)
{
if (URL != null)
{
if (Width == 0)
{
Alert(page, "頁面寬度和高度不能為零!");
return;
}
string str = "<script language='javascript'><!--
"
+ "newwindow=window.open('" + URL + "','','location=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=" + Width + ",height=document.height');"
+ "newwindow.moveTo(screen.width-" + Width + ",0);newwindow.resizeTo(" + Width + ",screen.height);"
+ "
// --></script>";
if (!page.IsClientScriptBlockRegistered("clientScript"))
page.RegisterClientScriptBlock("clientScript", str);
}
else
{
Alert(page, "頁面地址不能為空!");
}
}
/// <summary>
///13 靜態(tài)方法,打開一個IE窗口(無標題欄、工具欄、地址欄等),在屏幕的最右邊,上下位置在中間。
/// </summary>
/// <param name="page">頁面對象</param>
/// <param name="URL">頁面名稱</param>
/// <param name="Width">寬度</param>
/// <param name="Height">高度</param>
/// <example>
/// PublicJS.OpenIEWindowRight(page,"weihu.aspx",700,350);
/// </example>
public static void OpenIEWindowRight(System.Web.UI.Page page, string URL, int Width, int Height)
{
if (URL != null)
{
if (Width == 0 || Height == 0)
{
Alert(page, "頁面寬度和高度不能為零!");
return;
}
string str = "<script language='javascript'><!--
"
+ "newwindow=window.open('" + URL + "','','location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=" + Width + ",height=" + Height + "');"
+ "newwindow.moveTo(screen.width-" + Width + ",(screen.height-" + Height + ")/2);"
+ "
// --></script>";
if (!page.IsClientScriptBlockRegistered("clientScript"))
page.RegisterClientScriptBlock("clientScript", str);
}
else
{
Alert(page, "頁面地址不能為空!");
}
}
/// <summary>
/// 設置控件焦點
/// </summary>
/// <param name="kongjianmc">控件字符串</param>
public static void SheZhiJD(System.Web.UI.Page page, string kongjianmc)
{
string jiaoben = "";
if (kongjianmc != "")
{
jiaoben = "var control;";
jiaoben += "control = document.getElementById('" + kongjianmc + "');";
jiaoben += "if (control!=null) ";
jiaoben += "{document.all['" + kongjianmc + "'].focus();}";
page.RegisterStartupScript("focus", "<script type="text/javascript"><!--
" + jiaoben + "
// --></script>");
}
}
/// <summary>
///14 靜態(tài)方法,全屏打開一個IE窗口(無標題欄、工具欄、地址欄等)。
/// </summary>
/// <param name="page">頁面對象</param>
/// <param name="URL">頁面名稱</param>
/// <example>
/// PublicJS.OpenIEWindow(page,"weihu.aspx");
/// </example>
public static void OpenIEWindowFill(System.Web.UI.Page page, string URL)
{
if (URL != null)
{
string str = "<script language='javascript'><!--
"
+ "var Cwin=window.open('" + URL + "','','location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=(screen.availWidth),height=(screen.availheight),left=10,top=10');"
//+ "alert(screen.availWidth);alert(screen.availheight); Cwin.moveTo(0,0);"
+ "
// --></script>";
if (!page.IsClientScriptBlockRegistered("clientScript"))
page.RegisterClientScriptBlock("clientScript", str);
}
else
{
Alert(page, "頁面地址不能為空!");
}
}
}
}
復制代碼 代碼如下:
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">信息內容</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">信息內容</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>
/// 彈出對話框,轉向所指頁面
/// </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>
/// 彈出對話框,確實轉向所指頁面
/// </summary>
/// <param name="description">提示信息</param>
/// <param name="url">頁面</param>
/// <param name="PrintUrl">確定后轉向的頁面</param>
public static void MsgBoxRedrict(string description, string url, string PrintUrl)
{
HttpResponse Response;
Response = HttpContext.Current.Response;
Response.Write("<script language=JScript><!--
\n");
Response.Write("function prints()\n");
Response.Write("{\n if(confirm('" + description + "'))\n");
Response.Write("{window.location='" + PrintUrl + "';}\n");
Response.Write("else\n");
Response.Write("{window.location='" + url + "';}\n}\n");
Response.Write("prints();\n");
Response.Write("
// --></script>\n");
}
/// <summary>
/// 彈出對話框,轉向所指頁面
/// </summary>
/// <param name="description">提示信息</param>
public static void MsgBoxRedrict(string description)
{
HttpResponse Response;
Response = HttpContext.Current.Response;
Response.Write("<script language=JScript><!--
\n");
Response.Write("alert('" + description + "');\n");
Response.Write("history.go(-1);\n");
Response.Write("
// --></script>\n");
}
/// <summary>
///2 靜態(tài)方法,關閉一個網(wǎng)頁的父窗口,例如一個frame關閉其父窗口。
/// </summary>
/// <param name="page">頁面對象</param>
/// <example>
/// PublicJS.CloseParent(this);
/// </example>
public static void CloseParent(System.Web.UI.Page page)
{
string scriptString = "<script language=JavaScript><!--
";
scriptString += "window.parent.close();";
scriptString += "
// --></script>";
if (!page.IsClientScriptBlockRegistered("clientScript"))
page.RegisterClientScriptBlock("clientScript", scriptString);
}
/// <summary>
///2 靜態(tài)方法,關閉一個網(wǎng)頁窗口。
/// </summary>
/// <param name="page">頁面對象</param>
/// <example>
/// PublicJS.CloseParent(this);
/// </example>
public static void ClosePage(System.Web.UI.Page page)
{
string scriptString = "<script language=JavaScript><!--
";
scriptString += "window.close();";
scriptString += "
// --></script>";
if (!page.IsClientScriptBlockRegistered("clientScript"))
page.RegisterClientScriptBlock("clientScript", scriptString);
}
/// <summary>
///3 靜態(tài)方法,輸出一則消息后關閉一個模態(tài)網(wǎng)頁窗口并刷新父窗口
/// 前提條件是必須調用此類中的OpenModalDialog方法
/// 在該方法中自動生成刷新方法才能實現(xiàn)父頁面刷新。
/// </summary>
/// <param name="page">頁面對象</param>
/// <param name="page">輸出消息</param>
/// <example>
/// PublicJS.CloseModalDialog(this);
/// </example>
public static void CloseModalDialogMessage(System.Web.UI.Page page, string Message)
{
string scriptString = "<script language=JavaScript><!--
";
scriptString += "alert('" + Message + "');";
scriptString += "window.close();";
scriptString += "
// --></script>";
if (!page.IsClientScriptBlockRegistered("clientScript"))
page.RegisterClientScriptBlock("clientScript", scriptString);
}
/// <summary>
///3 靜態(tài)方法,關閉一個模態(tài)網(wǎng)頁窗口并刷新父窗口
/// 前提條件是必須調用此類中的OpenModalDialog方法
/// 在該方法中自動生成刷新方法才能實現(xiàn)父頁面刷新。
/// </summary>
/// <param name="page">頁面對象</param>
/// <example>
/// PublicJS.CloseModalDialog(this);
/// </example>
public static void CloseModalDialog(System.Web.UI.Page page)
{
string scriptString = "<script language=JavaScript><!--
";
scriptString += "window.close();";
scriptString += "
// --></script>";
if (!page.IsClientScriptBlockRegistered("clientScript"))
page.RegisterClientScriptBlock("clientScript", scriptString);
}
/// <summary>
/// 關閉模態(tài)網(wǎng)頁并傳值到父頁面
/// </summary>
/// <param name="page">頁面對象</param>
/// <param name="strValue">需要傳遞的值</param>
public static void CloseModalDialog(System.Web.UI.Page page, string strValue)
{
string scriptString = "<script language=JavaScript><!--
";
scriptString += "window.returnValue='" + strValue.Trim() + "';";
scriptString += "window.close();";
scriptString += "
// --></script>";
if (!page.IsClientScriptBlockRegistered("clientScript"))
page.RegisterClientScriptBlock("clientScript", scriptString);
}
/// <summary>
///4 靜態(tài)方法,關閉一個網(wǎng)頁窗口。
/// </summary>
/// <param name="page">頁面對象</param>
/// <example>
/// PublicJS.CloseWindow(this);
/// </example>
public static void CloseWindow(System.Web.UI.Page page)
{
string scriptString = "<script language=JavaScript><!--
";
scriptString += "window.opener=null;";
scriptString += "window.close();";
scriptString += "
// --></script>";
if (!page.IsClientScriptBlockRegistered("clientScript"))
page.RegisterClientScriptBlock("clientScript", scriptString);
}
/// <summary>
///5 靜態(tài)方法,執(zhí)行客戶端一小塊腳本語言,
///利用page的RegisterClientScriptBlock方法在客戶端注冊一段腳本,
///參數(shù)script無需包括html標記<script type="text/javascript"><!--
、
// --></script>。
/// </summary>
/// <param name="page">頁面對象</param>
/// <param name="script">javascript腳本</param>
/// <example>
/// PublicJS.ExecuteBlock(this,"alert("Hello");");
/// </example>
public static void ExecuteBlock(System.Web.UI.Page page, string script)
{
if (script != null)
{
string scriptString = "<script language=JavaScript><!--
";
scriptString += script;
scriptString += "
// --></script>";
if (!page.IsClientScriptBlockRegistered("clientScript9"))
page.RegisterClientScriptBlock("clientScript9", scriptString);
}
else
{
Alert(page, "JavaScript腳本不能為空!");
}
}
/// <summary>
///6 靜態(tài)方法,打開一個網(wǎng)頁對話框,并生成刷新頁面方法。
/// </summary>
/// <param name="page">頁面對象</param>
/// <param name="URL">頁面名稱</param>
/// <param name="Width">寬度</param>
/// <param name="Height">高度</param>
/// <example>
/// PublicJS.OpenModalDialog(page,"weihu.aspx",700,350);
/// </example>
public static void OpenModalDialog(System.Web.UI.Page page, string URL, int Width, int Height)
{
if (URL != null)
{
if (Width == 0 || Height == 0)
{
Alert(page, "頁面寬度和高度不能為零!");
return;
}
string scriptString = "<script language='javascript'><!--
";
scriptString += "function Refreshs()";
scriptString += "{";
//scriptString += "window.location.href= window.location.href;";
scriptString += "}";
scriptString += "window.showModalDialog('" + URL + "',window,'dialogHeight:" + Height + "px;dialogWidth:" + Width + "px;center:Yes;help:No;scroll:auto;resizable:No;status:No;');";
scriptString += "window.location.href= window.location.href;";
scriptString += "
// --></script>";
if (!page.IsStartupScriptRegistered("Startup"))
page.RegisterStartupScript("Startup", scriptString);
}
else
{
Alert(page, "頁面地址不能為空!");
}
}
/// <summary>
///7 靜態(tài)方法,打開一個模式對話框
/// </summary>
/// <param name="page">頁面對象</param>
/// <param name="URL">頁面名稱</param>
/// <param name="Attribute">屬性</param>
/// <param name="Width">寬度</param>
/// <param name="Height">高度</param>
/// <example>
/// PublicJS.OpenModalDialog(page,"weihu.aspx","scrollbars=yes,status=yes",700,350);
/// </example>
public static void OpenModalDialog(System.Web.UI.Page page, string URL, string Attribute, int Width, int Height)
{
if (URL != null)
{
if (Width == 0 || Height == 0)
{
Alert(page, "頁面寬度和高度不能為零!");
return;
}
if (Attribute == "")
Attribute = "center:Yes;help:No;scroll:No;resizable:No;status:No;";
string scriptString = "<script language='javascript'><!--
";
//scriptString += "function Refresh()";
//scriptString += "{";
scriptString += "window.showModalDialog('" + URL + "',window,'dialogHeight:" + Height + "px;dialogWidth:" + Width + "px;" + Attribute + "')";
//scriptString += " window.location.href= window.location.href;";
//scriptString += "}";
//scriptString += " Refresh();";
scriptString += "
// --></script>";
if (!page.IsStartupScriptRegistered("Startup"))
page.RegisterStartupScript("Startup", scriptString);
}
else
{
Alert(page, "頁面地址不能為空!");
}
}
/// <summary>
///8 靜態(tài)方法,打開一個無模式網(wǎng)頁對話框。
/// </summary>
/// <param name="page">頁面對象</param>
/// <param name="URL">頁面名稱</param>
/// <param name="Width">寬度</param>
/// <param name="Height">高度</param>
/// <example>
/// PublicJS.OpenDialog(page,"weihu.aspx",700,350);
/// </example>
public static void OpenDialog(System.Web.UI.Page page, string URL, int Width, int Height)
{
if (URL != null)
{
if (Width == 0 || Height == 0)
{
Alert(page, "頁面寬度和高度不能為零!");
return;
}
string str = "<script language='javascript'><!--
"
+ "window.open('" + URL + "','','location=no,status=no,menubar=no,scrollbars=auto,resizable=Yes,width=" + Width + ",height=" + Height + "')"
+ "
// --></script>";
if (!page.IsClientScriptBlockRegistered("clientScript"))
page.RegisterClientScriptBlock("clientScript", str);
}
else
{
Alert(page, "頁面地址不能為空!");
}
}
/// <summary>
///9 靜態(tài)方法,打開一個IE窗口(無標題欄、工具欄、地址欄等)。
/// </summary>
/// <param name="page">頁面對象</param>
/// <param name="URL">頁面名稱</param>
/// <param name="Width">寬度</param>
/// <param name="Height">高度</param>
/// <param name="Left">左邊距</param>
/// <param name="Top">上邊距</param>
/// <example>
/// PublicJS.OpenIEWindow(page,"weihu.aspx",700,350,10,20);
/// </example>
public static void OpenIEWindow(System.Web.UI.Page page, string URL, int Width, int Height, int Left, int Top)
{
if (URL != null)
{
if (Width == 0 || Height == 0)
{
Alert(page, "頁面寬度和高度不能為零!");
return;
}
string str = "<script language='javascript'><!--
"
+ "tt = window.open('" + URL + "','','location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=" + Width + ",height=" + Height + ",left=" + Left + ",top=" + Top + "'); tt.focus();"
+ "
// --></script>";
if (!page.IsClientScriptBlockRegistered("clientScript"))
page.RegisterClientScriptBlock("clientScript", str);
}
else
{
Alert(page, "頁面地址不能為空!");
}
}
/// <summary>
///9 靜態(tài)方法,打開一個IE窗口(無標題欄、工具欄、地址欄等)。
/// </summary>
/// <param name="page">頁面對象</param>
/// <param name="URL">頁面名稱</param>
/// <param name="Width">寬度</param>
/// <param name="Height">高度</param>
/// <param name="Left">左邊距</param>
/// <param name="Top">上邊距</param>
/// <example>
/// PublicJS.OpenIEWindow(page,"weihu.aspx",700,350,10,20);
/// </example>
public static void OpenIEWindows(System.Web.UI.Page page, string URL, int Width, int Height, int Left, int Top)
{
if (URL != null)
{
if (Width == 0 || Height == 0)
{
Alert(page, "頁面寬度和高度不能為零!");
return;
}
//string str = "<script language='javascript'><!--
"
// + "window.open('" + URL + "','','location=no,status=no,menubar=yes,scrollbars=yes,resizable=no,width=" + Width + ",height=" + Height + ",left=" + Left + ",top=" + Top + "');"
// + "
// --></script>";
string str = "<script language='javascript'><!--
"
+ "tt = window.open('" + URL + "','','location=no,status=no,toolbar=no,menubar=yes,scrollbars=yes,resizable=yes,fullscreen=no'); tt.focus();"
+ "
// --></script>";
if (!page.IsClientScriptBlockRegistered("clientScript"))
page.RegisterClientScriptBlock("clientScript", str);
}
else
{
Alert(page, "頁面地址不能為空!");
}
}
public static void OpenIEWindows(System.Web.UI.Page page, string URL, int Width, int Height)
{
if (URL != null)
{
if (Width == 0 || Height == 0)
{
Alert(page, "頁面寬度和高度不能為零!");
return;
}
string str = "<script language='javascript'><!--
";
str += "a = window.open(\"" + URL + "\", \"\", \"fullscreen=0,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1,width=" + Width + ",height=" + Height + "\", true);";
str += "a.focus();";
str += "
// --></script>";
if (!page.IsClientScriptBlockRegistered("clientScript"))
page.RegisterClientScriptBlock("clientScript", str);
}
else
{
Alert(page, "頁面地址不能為空!");
}
}
/// <summary>
///10 靜態(tài)方法,打開一個IE窗口(無標題欄、工具欄、地址欄等)。
/// </summary>
/// <param name="page">頁面對象</param>
/// <param name="URL">頁面名稱</param>
/// <example>
/// PublicJS.OpenIEWindow(page,"weihu.aspx");
/// </example>
public static void OpenIEWindow(System.Web.UI.Page page, string URL)
{
if (URL != null)
{
string str = "<script language='javascript'><!--
"
+ "var Cwin=window.open('" + URL + "','','location=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=screen.availWidth-20,height=screen.availHeight-20,left=10,top=10');"
+ "Cwin.resizeTo(screen.availWidth-20,screen.availHeight-20);"
+ "
// --></script>";
if (!page.IsClientScriptBlockRegistered("clientScript"))
page.RegisterClientScriptBlock("clientScript", str);
}
else
{
Alert(page, "頁面地址不能為空!");
}
}
/// <summary>
///11 靜態(tài)方法,打開一個IE窗口(無標題欄、工具欄、地址欄等)。
/// </summary>
/// <param name="page">頁面對象</param>
/// <param name="URL">頁面名稱</param>
/// <param name="Width">寬度</param>
/// <param name="Height">高度</param>
/// <example>
/// PublicJS.OpenIEWindow(page,"weihu.aspx",700,350);
/// </example>
public static void OpenIEWindow(System.Web.UI.Page page, string URL, int Width, int Height)
{
if (URL != null)
{
string str = "<script language='javascript'><!--
"
+ "var Cwin=window.open('" + URL + "','','location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=" + Width + ",height=" + Height + ",left=10,top=10');"
+ "Cwin.moveTo((screen.availWidth-" + Width + ")/2,(screen.availHeight-" + Height + ")/2);"
+ "
// --></script>";
if (!page.IsClientScriptBlockRegistered("clientScript"))
page.RegisterClientScriptBlock("clientScript", str);
}
else
{
Alert(page, "頁面地址不能為空!");
}
}
/// <summary>
///12 靜態(tài)方法,打開一個IE窗口(無標題欄、工具欄、地址欄等)
///在屏幕的最右邊,上下滿屏,寬度由參數(shù)指定。
/// </summary>
/// <param name="page">頁面對象</param>
/// <param name="URL">頁面名稱</param>
/// <param name="Width">寬度</param>
/// <example>
/// PublicJS.OpenIEWindowRight(page,"weihu.aspx",700);
/// </example>
public static void OpenIEWindowRight(System.Web.UI.Page page, string URL, int Width)
{
if (URL != null)
{
if (Width == 0)
{
Alert(page, "頁面寬度和高度不能為零!");
return;
}
string str = "<script language='javascript'><!--
"
+ "newwindow=window.open('" + URL + "','','location=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=" + Width + ",height=document.height');"
+ "newwindow.moveTo(screen.width-" + Width + ",0);newwindow.resizeTo(" + Width + ",screen.height);"
+ "
// --></script>";
if (!page.IsClientScriptBlockRegistered("clientScript"))
page.RegisterClientScriptBlock("clientScript", str);
}
else
{
Alert(page, "頁面地址不能為空!");
}
}
/// <summary>
///13 靜態(tài)方法,打開一個IE窗口(無標題欄、工具欄、地址欄等),在屏幕的最右邊,上下位置在中間。
/// </summary>
/// <param name="page">頁面對象</param>
/// <param name="URL">頁面名稱</param>
/// <param name="Width">寬度</param>
/// <param name="Height">高度</param>
/// <example>
/// PublicJS.OpenIEWindowRight(page,"weihu.aspx",700,350);
/// </example>
public static void OpenIEWindowRight(System.Web.UI.Page page, string URL, int Width, int Height)
{
if (URL != null)
{
if (Width == 0 || Height == 0)
{
Alert(page, "頁面寬度和高度不能為零!");
return;
}
string str = "<script language='javascript'><!--
"
+ "newwindow=window.open('" + URL + "','','location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=" + Width + ",height=" + Height + "');"
+ "newwindow.moveTo(screen.width-" + Width + ",(screen.height-" + Height + ")/2);"
+ "
// --></script>";
if (!page.IsClientScriptBlockRegistered("clientScript"))
page.RegisterClientScriptBlock("clientScript", str);
}
else
{
Alert(page, "頁面地址不能為空!");
}
}
/// <summary>
/// 設置控件焦點
/// </summary>
/// <param name="kongjianmc">控件字符串</param>
public static void SheZhiJD(System.Web.UI.Page page, string kongjianmc)
{
string jiaoben = "";
if (kongjianmc != "")
{
jiaoben = "var control;";
jiaoben += "control = document.getElementById('" + kongjianmc + "');";
jiaoben += "if (control!=null) ";
jiaoben += "{document.all['" + kongjianmc + "'].focus();}";
page.RegisterStartupScript("focus", "<script type="text/javascript"><!--
" + jiaoben + "
// --></script>");
}
}
/// <summary>
///14 靜態(tài)方法,全屏打開一個IE窗口(無標題欄、工具欄、地址欄等)。
/// </summary>
/// <param name="page">頁面對象</param>
/// <param name="URL">頁面名稱</param>
/// <example>
/// PublicJS.OpenIEWindow(page,"weihu.aspx");
/// </example>
public static void OpenIEWindowFill(System.Web.UI.Page page, string URL)
{
if (URL != null)
{
string str = "<script language='javascript'><!--
"
+ "var Cwin=window.open('" + URL + "','','location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=(screen.availWidth),height=(screen.availheight),left=10,top=10');"
//+ "alert(screen.availWidth);alert(screen.availheight); Cwin.moveTo(0,0);"
+ "
// --></script>";
if (!page.IsClientScriptBlockRegistered("clientScript"))
page.RegisterClientScriptBlock("clientScript", str);
}
else
{
Alert(page, "頁面地址不能為空!");
}
}
}
}
相關文章
asp.net在事件中啟動線程來打開一個頁面的實現(xiàn)方法
點擊一個按鈕做兩件事情,一件需要點擊按鈕馬上完成,另一件事情是點擊按鈕后做其他事情,不會的朋友一起來看看下面是如何實現(xiàn)的2014-11-11.NET中RDLC循環(huán)處理數(shù)據(jù)的應用分析
本篇文章介紹了,.NET中RDLC循環(huán)處理數(shù)據(jù)的應用分析。需要的朋友參考下2013-05-05Asp.net靜態(tài)方法之Grid轉DataTable方法實現(xiàn)步驟
GridView綁定DataTable后,如何獲取GridView綁定后顯示的值,在項目需求的背景下寫了一個靜態(tài)方法,經(jīng)過在項目中的使用,bug的修復,較為穩(wěn)定2013-04-04ASP.NET:把ashx寫到類庫里并在頁面上調用的具體方法
最近在調整博客的架構,進一步把表現(xiàn)和業(yè)務分離,所以要把之前用ashx搞的那些Http Handler放到類庫中,下面是具體的步驟及代碼2013-06-06.NET 6開發(fā)TodoList應用之實現(xiàn)ActionFilter
Filter在.NET Web API項目開發(fā)中也是很重要的一個概念,它運行在執(zhí)行MVC響應的Pipeline中執(zhí)行,允許我們將一些可以在多個Action之間重用的邏輯抽取出來集中管理。本文將詳細介紹一下.NET 6如何實現(xiàn)ActionFilter,感興趣的可以學習一下2021-12-12asp.net連接數(shù)據(jù)庫 增加,修改,刪除,查詢代碼
asp.net連接數(shù)據(jù)庫,實現(xiàn)增加,修改,刪除,查詢的四大功能完整代碼。2009-07-07ASP.NET?Core設置Ocelot網(wǎng)關限流
這篇文章介紹了ASP.NET?Core設置Ocelot網(wǎng)關限流的方法,文中通過示例代碼介紹的非常詳細。對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-04-04