Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

asp.net

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?

like image 569
Kheran Avatar asked Apr 22 '13 10:04

Kheran


People also ask

How do I open ASPX page as a popup window from code behind?

string url = "D13. aspx"; string s = "window. open('" + url + "', 'popup_window', 'width=300,height=100,left=100,top=100,resizable=yes');"; ClientScript. RegisterStartupScript(this.

How do I get the page to open in a new tab?

Hold Ctrl and left-click or middle-click the Reload button on the location/address bar to open the current page in a new tab.

How do I open a new tab with response redirect?

When the Button is clicked, first the SetTarget JavaScript function is called inside which the target property of the Form is set to _blank and after that the Server Side function is executed. Inside the Button Click event handler, the Response. Redirect code is executed and the Page opens in new Tab.


1 Answers

Try this one

string redirect = "<script>window.open('http://www.google.com');</script>"; 
Response.Write(redirect);
like image 145
Rajeev Kumar Avatar answered Oct 12 '22 12:10

Rajeev Kumar