通用类 Js 显示消息提示对话框,不输出页面内容,并返回上一页

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(); parent.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\">\r\n");
            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\">\r\n");
            Builder.AppendFormat("alert('{0}');\r\n", msg);
            Builder.AppendFormat(String.Format("{0}.location.href='{{0}}';\r\n", target), url);
            Builder.Append("</script>\r\n");
            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("\r\n<script type=\"text/javascript\">\r\n{0}\r\n</script>\r\n", script));           
        }


    }

 

posted @ 2012-08-29 16:00  暗尘掩月  阅读(475)  评论(0编辑  收藏  举报