我在 .aspx  中,为了弹出窗口,用下面的语句,可是弹出的窗口背景是一片空白,较难看,有什么办法吗?
Response.Write("<script> window.alert('请输入内容')</script>");背景为啥是空白的?

解决方案 »

  1.   


    this.ClientScript.RegisterStartupScript(typeof(string), "alert", "alert('请输入内容');", true);
      

  2.   

            /// <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>");
            }
      

  3.   

    因为response.write输出的js在页面的头部,会首先执行,而alert会弹出对话框并阻塞,alert后面的html内容无法因为阻塞无法被渲染,显示为空白,只有等对话框返回后才继续显示
      

  4.   


    alert后面的html内容无法因为阻塞无法被渲染->alert后面的html内容因为阻塞无法被渲染
      

  5.   

    如果Form runt=server 那么(有服务器控件)Page.ClientScript.RegisterStartupScript(Page.GetType(), "error", "alert('xxxxxxxxxxxxx!');", true);

    this.ClientScript.RegisterStartupScript(typeof(string), "alert", "alert('请输入内容');", true);如果没服务器控件,上面的代码则无效
    Response.Write(" <script> window.alert('请输入内容') </script>");背景是白色的也是正常的,因为只有等对话框返回后才继续显示