关于asp.net跳转新窗口,导致父窗口关闭的方法

最近修改以前的代码发现有个导出功能,导出之后父窗口关闭了,以前没有测出问题.................现已修改,

原来:

Response.Write("<script  type='text/javascript'>window.open('/File/" + dateStr + ".xls','_blank');</script>");

现在:

 this.ClientScript.RegisterStartupScript(this.GetType(), "", "<script  type='text/javascript'>window.open('/File/" + dateStr + ".xls','_blank');</script>");

关于一些可能会出现的错误/问题:

C# 从后台执行前台代码时失效

Page.ClientScript.RegisterStartupScript(this.GetType(), "",js)不执行;

原因一:

前台页缺少<form id="form1" runat="server"></form>标签 加上即可

原因二:

如果一个页面 顺序执行多个Page.ClientScript.RegisterStartupScript(this.GetType(), "",js)且 RegisterStartupScript方法的第二个参数为脚本的Key都为空或为相同的值 则只执行第一个脚本

此时把key区别开即可

推荐:http://blog.csdn.net/u013192680/article/details/38121637

 

posted @ 2017-12-04 17:34  ly丶乐  阅读(488)  评论(0编辑  收藏  举报