C# 在新标签页中打开页面 asp.net
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11888892/
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 page in new tab asp.net
提问by Nurlan
I am writing a project using ASP.NET C#.
我正在使用 ASP.NET C# 编写一个项目。
I want to implement linkbutton click event to open new page in a new tab, but before I have to create new session variable. I have tried this:
我想实现链接按钮单击事件以在新选项卡中打开新页面,但在我必须创建新会话变量之前。我试过这个:
protected void LinkButton_Click3(Object sender, EventArgs e)
{
string p_id = (sender as LinkButton).CommandArgument;
Session["p_id"] = p_id;
Response.Write("<script type='text/javascript'> window.open('details.aspx','_blank'); </script>");
}
But it doesn't work anyway.
但无论如何它都不起作用。
回答by rs.
Try this, call this function on button click or document.ready only on page where you want to redirect from.
试试这个,在单击按钮或文档时调用此函数。仅在您要重定向的页面上调用此函数。
<script type="text/javascript">
function newTab()
{
if (opener.document.getElementById("aspnetForm").target != "_blank") return;
opener.document.getElementById("aspnetForm").target = "";
opener.document.getElementById("aspnetForm").action = opener.location.href;
}
</script
or add this to linkbutton html
或将此添加到链接按钮 html
OnClientClick="aspnetForm.target ='_blank';"
回答by StingyHyman
Based on your comments, you should disable your popup blocker.
根据您的评论,您应该禁用弹出窗口阻止程序。
回答by user3621589
Sometimes it works for me to just declare whatever I would invoke dynamically from the administrated code into a javascript function and just call it from within with the RegisterClientScriptBlock method in ClientScript class:
有时,我只需将我将从管理代码动态调用的任何内容声明为 javascript 函数,然后使用 ClientScript 类中的 RegisterClientScriptBlock 方法从内部调用它:
Daclare the window.open function:
Daclare window.open 函数:
<script type="text/javascript">
function SetRedirect(URI) {
window.open(URI, "Details", "menubar=no, location=no, resizable=yes, scrollbars=yes, status=yes, width = 1200, height = 600");
}
</script>
And from within the code behind class just a gateway caller to this function like:
从类背后的代码中,只是一个网关调用者到这个函数,如:
void MessageGateway(string URI)
{
this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(),
"logCallBack", @"<script type=""text/javascript"">SetRedirect('" + URI + "');</script>");
}
And that's it, you may call this gateway with your stuff as normally you do,
就是这样,你可以像往常一样用你的东西调用这个网关,
MessageGateway(string.Format("../IRMQueryPO.aspx?id={0}", e.Item.Cells[2].Text));
You can try tweeking the "target" parameter with "_blank" in order to open a tab instead a window, it's just a matter of the flavor your solution points in.
您可以尝试使用“_blank”调整“目标”参数以打开选项卡而不是窗口,这只是您的解决方案所指向的风格的问题。

