using System;
using System.Text;
using System.Web.UI;
namespace XXXX.Common
{
public class Js
{
/// <summary>
/// 显示消息提示对话框,不输出页面内容,并返回上一页
/// </summary>
/// <param name="page">
当前页面指针</param>
/// <param name="msg">提示信息</param>
/// <returns></returns>
public static void ShowAndBack(System.Web.UI.Page page, string msg)
{
page.Response.Clear();
page.Response.Write(String.Format("<script type="text/
javascript">alert("{0}");history.back();</script>", msg));
page.Response.End();
}
/// <summary>
/// 显示消息提示对话框,不输出页面内容,并调用Thickbox方法关闭
弹出窗口
/// </summary>
/// <param name="page">当前页面指针</param>
/// <param name="msg">提示信息</param>
public static void ShowAndClose(System.Web.UI.Page page, string msg)
{
page.Response.Clear();
page.Response.Write(String.Format("<script type="text/javascript">alert("{0}");", msg));
page.Response.Write("try{frameElement.api.opener.$.dialog.list["dialogWindow"].close();}catch(e){ }</script>");
page.Response.End();
}
/// <summary>
/// 显示消息提示对话框,不输出页面内容,并调用Thickbox方法关闭弹出窗口,再刷新父级页面
/// </summary>
/// <param name="page">当前页面指针</param>
/// <param name="msg">提示信息</param>
public static void ShowCloseRefresh(System.Web.UI.Page page, string msg)
{
page.Response.Clear();
page.Response.Write(String.Format("<script type="text/javascript">alert("{0}");", msg));
page.Response.Write("try{frameElement.api.opener.$.dialog.list["dialogWindow"].close(); frameElement.api.opener.location.reload();}catch(e){ }</script>");
page.Response.End();
}
/// <summary>
/// 显示消息提示对话框
/// </summary>
/// <param name="page">当前页面指针,一般为this</param>
/// <param name="msg">提示信息</param>
public static void Show(System.Web.UI.Page page, string msg)
{
ClientScriptManager cs = page.ClientScript;
cs.RegisterStartupScript(page.GetType(), "message", String.Format("<script type="text/javascript">alert("{0}");</script>", msg));
}
/// <summary>
/// 显示消息提示对话框,并进行
页面跳转
/// </summary>
/// <param name="page">当前页面指针,一般为this</param>
/// <param name="msg">提示信息</param>
/// <param name="url">跳转的目标URL</param>
public static void Show(System.Web.UI.Page page, string msg, string url)
{
StringBuilder Builder = new StringBuilder();
Builder.Append("<script type="text/javascript">rn");
Builder.AppendFormat("alert('{0}');", msg);
Builder.AppendFormat("top.location.href='{0}'", url);
Builder.Append("</script>");
page.Response.Clear();
page.Response.Write(Builder.ToString());
page.Response.End();
}
/// <summary>
/// 显示消息提示对话框,并进行页面跳转
/// </summary>
/// <param name="page">当前页面指针,一般为this</param>
/// <param name="msg">提示信息</param>
/// <param name="url">跳转的目标URL</param>
/// <param name="target">跳转目标窗口</param>
public static void Show( System.Web.UI.Page page, string msg, string url,string target )
{
StringBuilder Builder = new StringBuilder();
Builder.Append("<script type="text/javascript">rn");
Builder.AppendFormat("alert('{0}');rn", msg);
Builder.AppendFormat(String.Format("{0}.location.href='{{0}}';rn", target), url);
Builder.Append("</script>rn");
page.Response.Clear();
page.Response.Write(Builder.ToString());
page.Response.End();
}
/// <summary>
/// 输出自定义
脚本信息
/// </summary>
/// <param name="page">当前页面指针,一般为this</param>
/// <param name="script">输出脚本</param>
public static void ResponseScript(System.Web.UI.Page page, string script)
{
ClientScriptManager cs = page.ClientScript;
cs.RegisterStartupScript(page.GetType(), "message", String.Format("rn<script type="text/javascript">rn{0}rn</script>rn", script));
}
}
}