我在 .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.   

    使用Response.Write()的方式很容易让CSS失效
    还是使用下面这个比较好:
    this.ClientScript.RegisterStartupScript(typeof(string), "alert", "alert('请输入内容');", true);
      

  5.   

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

  6.   

    这段代码在执行的时候会在页面的最顶部生成对应的html代码.而由于ASP.NET 2.0默认采用http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd文档类型定义,它就要求在<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">的前面不能有任何输出。this.RegisterStartupScript("show","<script language='javascript'></script>");
      

  7.   

    要让它不变白,可以考虑客户段的方式或ajax的方式
      

  8.   

    Response.Write()输出脚本是在生成的html的最顶端的.你打开页面,查看一下html源.看一下最顶端就明白了.
    最顶端时,底下的<body></body>内容还没加载..所是空白的