Kheran
Kheran

Reputation: 552

How to open a page in a new window or tab from code-behind

So I have a webapplication where I select a value from a dropdownlist. When this value is selected, I want to load another page in a new window.

I tried this:

ScriptManager.RegisterStartupScript(Page, typeof(Page), "OpenWindow", "window.open('Default.aspx', '_blank');", true);

It does open the page, but not in a new window/tab. It opens it in the current opened page.

Alternatively I tried:

ClientScript.RegisterStartupScript(this.GetType(), "OpenWin", "<script>openDashboardPage()</script>");

and

HttpContext.Current.Response.Write("<SCRIPT LANGUAGE='JavaScript'>window.open('Default.aspx', '_new');</SCRIPT>");

They all behave in the same fashion. I just loads the page in the existing window. I tried it in both Firefox and Chrome, thinking it might be a browser thing, but they both behaved the same.

How do I open a new window?

Upvotes: 13

Views: 111211

Answers (5)

navya
navya

Reputation: 144

You can use scriptmanager.registerstartupscript to call a JavaScript function.

Inside that function, you can open a new window.

Upvotes: -1

Rajeev Kumar
Rajeev Kumar

Reputation: 4963

Try this one

string redirect = "<script>window.open('http://www.google.com');</script>"; 
Response.Write(redirect);

Upvotes: 21

Saiyam
Saiyam

Reputation: 138

Use:

Target= "_blank" property of anchor tag

Upvotes: 1

jlvaquero
jlvaquero

Reputation: 8785

This code works for me:

Dim script As String = "<script type=""text/javascript"">window.open('" & URL.ToString & "');</script>"
ClientScript.RegisterStartupScript(Me.GetType, "openWindow", script)

Upvotes: 3

Connor
Connor

Reputation: 645

Target= "_blank"

This does it in html, give it a try in C#

Upvotes: -1

Related Questions