ASP.NET Response.Redirect打开一个新的浏览器窗口?

时间:2013-08-07 04:43:56

标签: c# asp.net

我们正在使用ASP.NET Webforms(而不是MVC)。

我的问题是: 是否可以使用回发打开新的浏览器窗口,然后使用各种Response.Redirect?

3 个答案:

答案 0 :(得分:7)

我没有遇到Response.Redirect可以导航打开新窗口的实例。

以下是一种不使用Response.Redirect的方法:您可以尝试:

ScriptManager.RegisterStartupScript(this, typeof(string), "New_Window", "window.open( 'http://www.website.com', null, 'height=800,width=1280,status=yes,toolbar=yes,menubar=yes,location=no' );", true);

答案 1 :(得分:1)

简短回答?否。

答案很长:

ASP.NET是服务器端框架,而浏览器窗口的概念是客户端框架。 Response.Redirect只是最终发送Location: [whatever the new url is]标头作为输出流的一部分。事实上,几乎所有浏览器都通过加载该标头中的URL来处理该标头。

最简单的方法是在回发中使用javascript打开新窗口,如JLC007's回答中所述。另一种可能的选择是在渲染表单上使用target属性。

答案 2 :(得分:0)

试试这个

 ScriptManager.RegisterStartupScript(this, typeof(string), "openWindow", 
     "window.open( 'http://www.website.com', target="_blank", 
     'height=800,width=1280,status=yes,toolbar=yes,menubar=yes,location=no' );",
       true);