博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

c# 几种常见的弹框方法

Posted on 2016-04-21 16:33  preface小贝  阅读(536)  评论(0编辑  收藏  举报

1.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('第一行');</script>"); 

 

2.Page.RegisterStartupScript("", "<script>alert('第一行');</script>");  

 

3.Response.Write("<script>alert('第一行');</script>");  

 

另外注意:

1、如果alert的内容要换行,则需要加转义字符//n或//r//n,如:

ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('第一行//n第二行');</script>");<br />  

2、Response.Write输出,会破坏页面的结构,所以页面上的样式就会混乱,应该是在后台注册脚本模式。registerstartupscript(this.updatepanel1, this.gettype(), "updatepanel1", "alert(1)", true);