为了账号安全,请及时绑定邮箱和手机立即绑定

弹出消息对话框类

标签:
JavaScript

using System.Text;

namespace DotNet.Utilities
 {
     //页面中弹出对话框
     public class MessageBox
     {
         private MessageBox()
         {
         }

        #region 显示消息提示对话框
         /// <summary>
         /// 显示消息提示对话框
         /// </summary>
         /// <param name="page">当前页面指针,一般为this</param>
         /// <param name="msg">提示信息</param>
         public static void Show(System.Web.UI.Page page, string msg)
         {
            // page.RegisterStartupScript("message", "<script language='javascript' defer>alert('" + msg.ToString() + "');</script>");
             page.ClientScript.RegisterStartupScript(page.GetType(), "message", "<script language='javascript' defer>alert('" + msg.ToString() + "');</script>");
         }

        #endregion

        #region 控件点击 消息确认提示框

        /// <summary>
         /// 控件点击 消息确认提示框
         /// </summary>
         /// <param name="page">当前页面指针,一般为this</param>
         /// <param name="msg">提示信息</param>
         public static void ShowConfirm(System.Web.UI.WebControls.WebControl Control, string msg)
         {
             //Control.Attributes.Add("onClick","if (!window.confirm('"+msg+"')){return false;}");
             Control.Attributes.Add(" "return confirm('" + msg + "');");
         }
         #endregion

        #region 显示消息提示对话框,并进行页面跳转
         /// <summary>
         /// 显示消息提示对话框,并进行页面跳转
         /// </summary>
         /// <param name="page">当前页面指针,一般为this</param>
         /// <param name="msg">提示信息</param>
         /// <param name="url">跳转的目标URL</param>
         public static void ShowAndRedirect(System.Web.UI.Page page, string msg, string url)
         {
             StringBuilder Builder = new StringBuilder();
             Builder.Append("<script language='javascript' defer>");
             Builder.AppendFormat("alert('{0}');", msg);
             Builder.AppendFormat("location.href='{0}'", url);
             Builder.Append("</script>");
             //page.RegisterStartupScript("message", Builder.ToString());
             page.ClientScript.RegisterStartupScript(page.GetType(), "message", Builder.ToString());

        }
         

        public static void ShowAndRedirect(System.Web.UI.Page page, string msg, string url, bool top)
         {
             StringBuilder Builder = new StringBuilder();
             Builder.Append("<script language='javascript' defer>");
             Builder.AppendFormat("alert('{0}');", msg);
             if (top == true)
             {
                 Builder.AppendFormat("top.location.href='{0}'", url);
             }
             else
             {
                 Builder.AppendFormat("location.href='{0}'", url);
             }
             Builder.Append("</script>");
            // page.RegisterStartupScript("message", Builder.ToString());
             page.ClientScript.RegisterStartupScript(page.GetType(), "message", Builder.ToString());

        }

        #endregion

        #region 输出自定义脚本信息
         /// <summary>
         /// 输出自定义脚本信息
         /// </summary>
         /// <param name="page">当前页面指针,一般为this</param>
         /// <param name="script">输出脚本</param>
         public static void ResponseScript(System.Web.UI.Page page, string script)
         {
             //page.RegisterStartupScript("message", "<script language='javascript' defer>" + script + "</script>");
             page.ClientScript.RegisterStartupScript(page.GetType(), "message", "<script language='javascript' defer>" + script + "</script>");
         }

        #endregion

    }
 }

点击查看更多内容
TA 点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
  • 推荐
  • 评论
  • 收藏
  • 共同学习,写下你的评论
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消