我原先用的是Response.Write("<script>alert('你好!');</script>");
运行后会先清除屏幕(呈白色),然后弹出一个'你好!'的信息窗口。点击'确定'按钮后发现页面的格式遭到破坏,变得乱七八糟的了,说明上面的语句会干扰并使css失效。
由于不希望在弹出信息窗口之前先要清除屏幕,故改用:
Page.ClientScript.RegisterStartupScript(this.GetType(), "MyScript", "<script>alert('你好!');</script>");
这样的语句,它的好处是不会清除屏幕。但有时在这一句的后面加上一句跳转的语句,如:
Page.ClientScript.RegisterStartupScript(this.GetType(), "MyScript", "<script>alert('你好!');</script>");
Response.Redirect("~/index.aspx"); 
第一句就不执行了,只执行跳转语句。不知是怎么回事?

解决方案 »

  1.   

    Page.ClientScript.RegisterStartupScript(this.GetType(), "MyScript", "<script>alert('你好!');</script>");
    ---改用Page.Ch
      

  2.   

    直接写Page.ClientScript.RegisterStartupScript(this.GetType(), "MyScript", "<script>alert('你好!');window.localtion='~/index.aspx';</script>");
      

  3.   

    顶,
    Page.ClientScript.RegisterStartupScript(this.GetType(),   "MyScript",   " <script >alert( "你好! ");window.localtion= "~/index.aspx "; </script >");
    好像不行吧!!