I need to open an aspx page in a new tab, I searched differents solutions, but I've only found codes that open pop-ups and the browser blocks. I need to do it in the code behind
I hope somebody help me, THANKS.
I need to open an aspx page in a new tab, I searched differents solutions, but I've only found codes that open pop-ups and the browser blocks. I need to do it in the code behind
I hope somebody help me, THANKS.
You cannot open a new page from code behind. Instead, you need to open at client side.
protected void Button1_Click(object sender, EventArgs e)
{
string url = "http://www.stackoverflow.com";
string script = string.Format("window.open('{0}');", url);
Page.ClientScript.RegisterStartupScript(this.GetType(),
"newPage" + UniqueID, script, true);
/* Use this if post back is via Ajax
ScriptManager.RegisterStartupScript(Page, Page.GetType(),
"newPage" + UniqueID, script, true); */
}
The problem of opening at client side is sometime pop-up blocker blocks the page.
The short answer is: you can't.
You especially can't do it from the server — there, you have zero access to browser functionality.
And on the client side of thing, you have very little direct access to browser functionality outside your own "window".
The best you can do is open a new window with a target window name of _blank
. You can do that with HTML, thus:
<a href="http://some-url" target="_blank" >Link Text</a>
When the user clicks the link a new window should open (but, see below).
You can do it with javascript, thus:
window.open( "http://some-url", "_blank", "comma,delimited,list,of,window,features" ) ;
What happens then is entirely dependent on the browser and how the user has configured it:
One might note, too that a straight link without a window name might open in a new tab or window, too. For instance, I have my Firefox configured to open off-domain links in a new tab by default, and to open all target='_blank'
links in a new tab rather than a new window.