1

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!!!

HP1104
  • 93
  • 9
  • Potential dupe: http://stackoverflow.com/questions/16896284/opening-a-url-in-a-new-tab – Sensei James Sep 19 '16 at 15:29
  • In that solution they are using OnClientClick and OnClick methods. I can not do it because i have to execute .net code first and then only redirect to both pages. – HP1104 Sep 19 '16 at 16:49

3 Answers3

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!

Gustavo Cantero
  • 440
  • 6
  • 9
0

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");
}
Gopalakrishnan
  • 507
  • 1
  • 5
  • 15
  • Hello, Thanks for your answer. I can not do it because i have to execute code before redirect to both pages. – HP1104 Sep 19 '16 at 16:48
0

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);
Amir H KH
  • 351
  • 2
  • 18