C# 如何从代码隐藏在新窗口或选项卡中打开页面
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16145187/
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
How to open a page in a new window or tab from code-behind
提问by Kheran
So I have a webapplication where I select a value from a dropdownlist. When this value is selected, I want to load another page in a new window.
所以我有一个网络应用程序,我从下拉列表中选择一个值。选择此值后,我想在新窗口中加载另一个页面。
I tried this:
我试过这个:
ScriptManager.RegisterStartupScript(Page, typeof(Page), "OpenWindow", "window.open('Default.aspx', '_blank');", true);
It does open the page, but not in a new window/tab. It opens it in the current opened page.
它确实打开了页面,但不在新窗口/选项卡中。它在当前打开的页面中打开它。
Alternatively I tried:
或者我试过:
ClientScript.RegisterStartupScript(this.GetType(), "OpenWin", "<script>openDashboardPage()</script>");
and
和
HttpContext.Current.Response.Write("<SCRIPT LANGUAGE='JavaScript'>window.open('Default.aspx', '_new');</SCRIPT>");
They all behave in the same fashion. I just loads the page in the existing window. I tried it in both Firefox and Chrome, thinking it might be a browser thing, but they both behaved the same.
他们都以同样的方式行事。我只是在现有窗口中加载页面。我在 Firefox 和 Chrome 中都尝试过,认为这可能是浏览器的问题,但它们的行为都一样。
How do I open a new window?
如何打开一个新窗口?
采纳答案by Rajeev Kumar
Try this one
试试这个
string redirect = "<script>window.open('http://www.google.com');</script>";
Response.Write(redirect);
回答by Connor
Target= "_blank"
This does it in html, give it a try in C#
这是在 html 中完成的,在 C# 中尝试一下
回答by navya
You can use scriptmanager.registerstartupscriptto call a JavaScript function.
您可以使用scriptmanager.registerstartupscript调用一个JavaScript function.
Inside that function, you can open a new window.
在该函数中,您可以打开一个新窗口。
回答by jlvaquero
This code works for me:
这段代码对我有用:
Dim script As String = "<script type=""text/javascript"">window.open('" & URL.ToString & "');</script>"
ClientScript.RegisterStartupScript(Me.GetType, "openWindow", script)
回答by Saiyam
Use:
用:
Target= "_blank" property of anchor tag
Target="_blank" 锚标签属性

