1、弹出JavaScript小窗口
public static void Alert(string message) { string js = "<script language='JavaScript'>alert('{0}');history.go(-1);</script>"; HttpContext.Current.Response.Write(string.Format(js, message)); }
2、弹出消息框并且转向到新的URL
public static void Alert(string message, string toURL) { string js = "<script language='JavaScript'>alert('{0}');window.location.replace('{1}')</script>"; HttpContext.Current.Response.Write(string.Format(js, message, toURL)); }
3、出消息框并且转向到指定FRAME的新URL public static void Alert(string message, string frame, string toURL) { string js = "<script language='JavaScript'>alert('{0}');{1}.location.replace('{2}')</script>"; HttpContext.Current.Response.Write(string.Format(js, message, frame, toURL)); }
4、服务器端弹出confirm对话框,并根据选择触发某按钮点击事重定向URL。 public static void ConfirmRedirect(Page page, string sMessage, string sUrl) { page.ClientScript.RegisterStartupScript(typeof(System.String), "", "<script language='javascript' type='text/javascript' defer='defer'> if (confirm('" + sMessage + "')==true){ window.location.href = '" + sUrl + "';}</script>"); }
5、服务器端弹出confirm对话框,并根据选择触发某按钮点击事件。 public static void Confirm(Page page, string sMessage, string btn) { page.ClientScript.RegisterStartupScript(typeof(System.String), "", "<script language='javascript' type='text/javascript' defer='defer'> if (confirm('" + sMessage + "')==true){document.forms(0)." + btn + ".click();}</script>"); }
6、服务器端弹出confirm对话框,并根据选择触发某按钮点击事重定向URL,包括“确定”和“取消”时的操作 public static void Confirm(Page page, string sMessage, string btn_Redirect_Yes, string btn_Redirect_No) { page.ClientScript.RegisterStartupScript(typeof(System.String), "", "<script language='javascript' type='text/javascript' defer='defer'> if (confirm('" + sMessage + "')==true){document.forms(0)." + btn_Redirect_Yes + ".click();}btn_Redirect_Yes{document.forms(0)." + btn_Redirect_No + ".click();}</script>"); }
7、回到历史页面 public static void GoHistory(int value) { string js = "<script language='JavaScript'>history.go({0});</script>"; HttpContext.Current.Response.Write(string.Format(js, value)); }
8、关闭当前窗口 public static void CloseWindow() { string js = "<script language='JavaScript'>parent.opener=null;window.close();</script>"; HttpContext.Current.Response.Write(js); HttpContext.Current.Response.End(); }
9、父窗口打开指定页面 public static void RefreshParent(string url) { string js = "<script language='JavaScript'>window.opener.location.href='{0}';window.close();</script>"; HttpContext.Current.Response.Write(string.Format(js, url)); }
10、刷新窗口 public static void RefreshWindow() { string js = "<script language='JavaScript'>opener.location.reload();</script>"; HttpContext.Current.Response.Write(js); }
11、 打开指定大小的新窗体 public static void OpenWindow(string url, int width, int heigth, int top, int left) { string js = "<script language='JavaScript'>window.open('{0}', '', 'width={1}, height={2}, top={3}, left={4}, location=no, menubar=no, resizable=yes, scrollbars=yes, status=yes, titlebar=no, toolbar=no, directories=no');</script>"; HttpContext.Current.Response.Write(string.Format(js, url, width, heigth, top, left)); }
12、打开新窗体 public static void OpenWindow(string url) { string js = "<script language='JavaScript'>window.open('{0}');</script>"; HttpContext.Current.Response.Write(string.Format(js, url)); }
13、 转向指定窗口指定Url的页面 public static void JsGoTo(string window, string url) { string js = "<script language='JavaScript'>{0}.location.replace('{1}');</script>"; HttpContext.Current.Response.Write(string.Format(js, window, url)); }
14、转向指定Url的页面 public static void JavaScriptLocationHref(string url) { JsGoTo("window", url); }
15、转向top指定Url的页面 public static void TopGoTo(string url) { JsGoTo("top", url); }
16、转向parent指定Url的页面 public static void ParentGoTo(string url) { JsGoTo("parent", url); }
17、打开指定大小位置的模式对话框 public static void ShowModalDialogWindow(string webFormUrl, int width, int height, int top, int left) { string features = "dialogWidth:" + width.ToString() + "px" + ";dialogHeight:" + height.ToString() + "px" + ";dialogLeft:" + left.ToString() + "px" + ";dialogTop:" + top.ToString() + "px" + ";center:yes;help=no;resizable:no;status:no;scroll=yes"; ShowModalDialogWindow(webFormUrl, features); }
18、打开模式窗口 public static void ShowModalDialogWindow(string webFormUrl, string features) { string js = ShowModalDialogJavascript(webFormUrl, features); HttpContext.Current.Response.Write(js); }
19、返回模式窗口脚本 public static string ShowModalDialogJavascript(string webFormUrl, string features) { string js = "<script language=javascript>showModalDialog('" + webFormUrl + "','','" + features + "');</script>"; return js; }