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

痴心易碎 提交于 2020-04-30 07:23:20

问题


When user will click on button, I want to open one .aspx/.html page in different tab and open one .aspx/.html page in same tab.

Sample code:

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

Thanks in Adance!!!


回答1:


No, the response redirect writes in the http's header the "location" value and can only have one, but you can write a javascript like the next for do what you need:

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

Good luck!




回答2:


We can achieve by using Javascript and code behind page

Call Javascript Window.Open() function on Clientclick property to open in new window.

and onClick call your code behine buttonClick Event to redirect on same window.

ASPX Page:

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

Code behind On Click function:

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



回答3:


This code not working on Chrome :

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

But you can use this code instead of window.location.href then its working in all browsers :

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


来源:https://stackoverflow.com/questions/39576169/is-it-possible-to-add-2-response-redirect-one-will-open-in-different-tab-and-ot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!