C# 在新窗口中打开asp.net页面
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19134524/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
open asp.net page in new window
提问by dotnetrocks
I'm trying to open asp.net page in new window while loading itself. I tried with the following code. But it is opening in the same window not in the new window.
我正在尝试在加载自身时在新窗口中打开 asp.net 页面。我尝试使用以下代码。但它是在同一个窗口中打开而不是在新窗口中打开。
protected void Page_Load(object sender, EventArgs e)
{
if (HttpContext.Current.Request.UserAgent != null)
{
var userAgent = HttpContext.Current.Request.UserAgent.ToLower();
if (userAgent.Contains("iphone;"))
{
// iPhone
Form.Target = "_blank";
}
}
}
Any help is appreciated. thanks !!
任何帮助表示赞赏。谢谢 !!
回答by Zaki
Use a Javascript in code behind to redirect :
在后面的代码中使用 Javascript 重定向:
Response.Write("<script>window.open('http://www.google.com.hk/','_blank');</script>");
Or use ScriptManagerand you can pass parameters too:
或者使用ScriptManager你也可以传递参数:
ScriptManager.RegisterStartupScript(Page, typeof(Page), "OpenWindow", "window.open('YourPage.aspx?Param=" + ParamX.ToString() + "');",true);
Or if you have a button you can use it as below:
或者,如果您有一个按钮,您可以按如下方式使用它:
Button1.OnClientClick="javascript:window.open('YourPage.aspx?Param=" + ParamX.ToString() + "');";
回答by anand360
this is what i done, just try this
这就是我所做的,试试这个
ScriptManager.RegisterStartupScript(Page, typeof(Page), "OpenWindow", "window.open('ViewDetails.aspx','mywindow','menubar=1,resizable=1,width=900,height=600');", true);