• 解决UpdatePanel无法直接弹出窗口的问题


    /// <summary>
        /// 自定义弹出窗口内容
        /// </summary>
        /// <param name="msg"></param>
        public static void AjaxShowWindows(string msg)
        {
            //myContext.Response.Write("<script>彈出窗口代碼(wondows.open(XXX));</script>");
            string script="彈出窗口代碼(wondows.open(XXX));"; //注意彈出窗口的ID,最好使用隨機,否則只能彈出一次
            ScriptManager.RegisterStartupScript((System.Web.UI.Page)HttpContext.Current.CurrentHandler, typeof(System.Web.UI.Page), "ShowWindows", script, true);
        }


    ==========參考代碼===========

    using System;
    using System.Collections.Generic;
    using System.Text;

    using System.Web;
    using System.Web.UI;

    public class ShowMessage
    {
        /// <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);
        }

        /// <summary>
        /// 自定义弹出窗口内容
        /// </summary>
        /// <param name="msg"></param>
        public static void AjaxShow(string msg)
        {
            //myContext.Response.Write("<script>alert('" + msg + "');</script>");
            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)
        {
            //myContext.Response.Write("<script>alert('" + msg + "');javascript:location='"+Url+"';</script>");
            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)
            {
                //myContext.Response.Write("<script>alert('" + msg + "');javascript:location='"+Url+"';</script>");
                ScriptManager.RegisterStartupScript((System.Web.UI.Page)HttpContext.Current.CurrentHandler, typeof(System.Web.UI.Page), "ShowMessage", "alert('" + msg + "');javascript:location='" + url + "';", true);
            }
            else
            {
                //myContext.Response.Write("<script>alert('" + msg + "');javascript:location='"+Url+"';</script>");
                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)
            {
                // myContext.Response.Write("<script>alert('" + msg + "');javascript:window.close();</script>");
                ScriptManager.RegisterStartupScript((System.Web.UI.Page)HttpContext.Current.CurrentHandler, typeof(System.Web.UI.Page), "ShowMessage", "alert('" + msg + "');javascript:window.close();", true);
            }
            else
            {
                //myContext.Response.Write("<script>alert('" + msg + "');</script>");
                ScriptManager.RegisterStartupScript((System.Web.UI.Page)HttpContext.Current.CurrentHandler, typeof(System.Web.UI.Page), "ShowMessage", "alert('" + msg + "');", true);
            }
        }
    }

    转贴自 http://kb.cnblogs.com/a/1336111/

  • 相关阅读:
    转Vtype扩展
    Can't connect to MySQL server on 'ip' (13)
    观察者+js 模式
    (转)ASP.NET架构分析
    sql得到时间
    Js+XML 操作 (转)
    js中的math对象
    property和attribute的区别
    CSS样式定义
    linux 开启 mount
  • 原文地址:https://www.cnblogs.com/luyesql/p/1716835.html
Copyright © 2020-2023  润新知