是否可以使用 C# 添加 2 Response.Redirect,一个将在不同的选项卡中打开,另一个将在同一选项卡中打开?

Is it possible to add 2 Response.Redirect, one will open in different tab and other one will open in same tab, using C#?

当用户单击按钮时,我想在不同的选项卡中打开一个 .aspx/.html 页面并在同一选项卡中打开一个 .aspx/.html 页面。

示例代码:

string redirect = "<script>window.open('../User/Profile.html');</script>";
Response.Write(redirect);
Response.Redirect("../User/NewUser.aspx",true);

在此致谢!!!

不,响应重定向在 http 的 header 中写入 "location" 值并且只能有一个,但是您可以像下一个一样写一个 javascript 来做您需要的:

window.open('../User/Profile.html', 'tabName');
window.location.href = '../User/NewUser.aspx';

祝你好运!

我们可以通过使用Javascript和代码隐藏页面

来实现

在 Client 上调用 Javascript Window.Open() 函数单击 属性 以在新的 window 中打开。

和 onClick 在相同的 window.

上调用您的代码 behine buttonClick 事件以重定向

ASPX 页面:

  <asp:Button ID="Button1" runat="server" Text="Button"   OnClick="Button1_Click" OnClientClick="javascript:window.open('http://google.com','_blank');return true;" />

点击函数背后的代码:

protected void Button1_Click(object sender, EventArgs e)
{
    Response.Redirect("http://google.com");
}

此代码不适用于 Chrome :

window.location.href = '../User/NewUser.aspx';

但是您可以使用此代码代替 window.location.href 然后它在所有浏览器中工作:

setTimeout(function(){document.location.href = "page.html"},500);