MessageBox页面消息弹出框类_.NET_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > .NET > MessageBox页面消息弹出框类

MessageBox页面消息弹出框类

 2013/7/29 15:09:33  水手哥  博客园  我要评论(0)
  • 摘要:MessageBox页面消息弹出框类:publicclassMessageBox{///<summary>///自定义弹出窗口内容,不跳转///</summary>///<paramname="page"></param>///<paramname="msg"></param>publicstaticvoidShow(System.Web.UI.Pagepage,stringmsg){page.ClientScript
  • 标签:

MessageBox页面消息弹出框类:

public class MessageBox
    {
        /// <summary>
        /// 自定义弹出窗口内容,不跳转
        /// </summary>
        /// <param name="page"></param>
        /// <param name="msg"></param>
        public static void Show(System.Web.UI.Page page, string msg)
        {
            page.ClientScript.RegisterStartupScript(page.GetType(), "ShowMessage", "alert('" + msg + "');", true);
        }
        /// <summary>
        /// 自定义弹出窗口内容,并跳转
        /// </summary>
        /// <param name="page"></param>
        /// <param name="msg"></param>
        /// <param name="returnUrl"></param>
        public static void Show(System.Web.UI.Page page, string msg, string returnUrl)
        {
            page.ClientScript.RegisterStartupScript(page.GetType(), "ShowMessage", "alert('" + msg + "');window.location.href='" + returnUrl + "';", true);
        }
        /// <summary>
        /// 自定义弹出窗口内容,并跳转
        /// </summary>
        /// <param name="page"></param>
        /// <param name="msg"></param>

        /// <param name="returnUrl"></param>
        public static void Show(System.Web.UI.Page page, string msg, string trueReturnUrl, string falseReturnUrl)
        {
            page.ClientScript.RegisterStartupScript(page.GetType(), "ShowMessage", "if(confirm('" + msg + "')){javascript:location='" + trueReturnUrl + "';}else{javascript:location='" + falseReturnUrl + "';}", true);
        }

        /*--------------------------------------------
         * 以下方法需要framework2.0+
         * ------------------------------------------*/
        /// <summary>
        /// 自定义弹出窗口内容
        /// </summary>
        /// <param name="msg"></param>
        public static void AjaxShow(string msg)
        {
            ScriptManager.RegisterStartupScript((System.Web.UI.Page)HttpContext.Current.CurrentHandler, typeof(System.Web.UI.Page), "ShowMessage", "alert('" + msg + "');", true);
        }

        /// <summary>
        /// 自定义弹出窗口内容并直接转向一个新的页面
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="url"></param>
        public static void AjaxShow(string msg, string url)
        {
            ScriptManager.RegisterStartupScript((System.Web.UI.Page)HttpContext.Current.CurrentHandler, typeof(System.Web.UI.Page), "ShowMessage", "alert('" + msg + "');javascript:location='" + url + "';", true);
        }
        /// <summary>
        /// 自定义弹出窗口内容并选择是直接转向,还是提示转向一个新的页面
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="isreturn"></param>
        /// <param name="url"></param>
        public static void AjaxShow(string msg, bool isreturn, string url)
        {
            if (!isreturn)
            {
                ScriptManager.RegisterStartupScript((System.Web.UI.Page)HttpContext.Current.CurrentHandler, typeof(System.Web.UI.Page), "ShowMessage", "alert('" + msg + "');javascript:location='" + url + "';", true);
            }
            else
            {
                ScriptManager.RegisterStartupScript((System.Web.UI.Page)HttpContext.Current.CurrentHandler, typeof(System.Web.UI.Page), "ShowMessage", "if(confirm('" + msg + "')){javascript:location='" + url + "';}", true);
            }

        }
        /// <summary>
        /// 自定义弹出窗口内容,自定义是否关闭当前页面
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="close"></param>
        public static void AjaxShow(string msg, bool close)
        {
            if (close)
            {
                ScriptManager.RegisterStartupScript((System.Web.UI.Page)HttpContext.Current.CurrentHandler, typeof(System.Web.UI.Page), "ShowMessage", "alert('" + msg + "');javascript:window.close();", true);
            }
            else
            {
                ScriptManager.RegisterStartupScript((System.Web.UI.Page)HttpContext.Current.CurrentHandler, typeof(System.Web.UI.Page), "ShowMessage", "alert('" + msg + "');", true);
            }
        }
    }

 

  • 相关文章
发表评论
用户名: 匿名