Sophie Huang
Time and tide wait for no man.

在程序中经常会使用到弹窗:Response.Write("<script>alert('弹窗内容');</script>");

但是点击确定按钮后导致前台样式乱掉,在这里记录下解决方法。

解决方法一:

加上一句解析格式的语句:

Response.Write("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">");

解决方法二:

使用微软已封装好的方法代替Response.Write:

ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script>alert('弹窗内容');</script>");

 

ps:方法二还可以用于控制.aspx页面的js方法。

例如在.aspx页面中有方法

function alertMsg(msg)

{

alert(msg);

}

在后台代码中使用ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script>alertMsg('需要显示的内容');</script>");

即可显示弹窗内容。

posted on 2013-09-06 11:41  Sophie Huang  阅读(426)  评论(0编辑  收藏  举报