tags:

views:

311

answers:

2

Hello Friends

I am using Asp.net c# develop web application

How can I open up a response.redirect in a new browser window?

e.g Response.Redirect(http://www.asp.net);

Thanks

+1  A: 

Unfortunately you cannot do this from the server, you will have to use client side code to create a new browser window. You could do this with the Javascript function window.open.

One way of doing this would be to embed the URL you wish to send the user to in a hidden input and then when the page renders have a Javascript function that would check that input for a value and if it found one it would do the window.open call.

Andrew Hare
+2  A: 

This is a quite common question, and the answer is that you can't.

The reason is that it's decided already when the browser sends the request to the server where the page will be loaded, so when the code starts running at the server it's too late to change where the page will be loaded.

You can add javascript to the page that will open a new window, but you still have to send a page back to the browser as a response to the request (i.e. you can't leave the current page in the browser, as the browser has already requested a page to replace it).

ClientScript.RegisterStartupScript(this.GetType(), "aspnet", "window.open('http://www.asp.net','_blank');", true);
Guffa
+1 Thanks for the idea. I also found this more complex solution: http://weblogs.asp.net/infinitiesloop/archive/2007/09/25/response-redirect-into-a-new-window-with-extension-methods.aspx
Dave