Mujassir Nasir
Mujassir Nasir

Reputation: 1730

Response.Redirect() in new window in Asp.Net

How can i do that i want to process some data on server side with c# and the new page should open in new window. Thanks in advance

Upvotes: 0

Views: 9844

Answers (2)

Guffa
Guffa

Reputation: 700840

You can't do that using Response.Write. As soon as the request is sent to the server, it's already decided where the requested page will be opened. So, when the server code runs, it's already too late to change where the page will be opened.

If you want to open the page in a new window, that has to be done before sending the request to the server. Instead of doing a postback, you should send a request with _blank as target. You can use a link for that:

<a href="Page.aspx" target="_blank">...</a>

You can use the window.open method in Javascript:

window.open('Page.aspx', '_blank');

Upvotes: 4

Tomislav Markovski
Tomislav Markovski

Reputation: 12366

Opening a new window in almost all browsers nowadays has to be invoked from a user click event. Almost all browsers (and this covers about 99% of cases) will block a popup that is invoked from a page load event, so I suggest you reconsider your solution, probably by showing a link that would open in new window.

What I would do, is open the new window on the click event, which would open your processing page, which in turn will redirect to whatever page you want. Basically, first open the popup with click event, and then do the redirect in your new page.

Upvotes: 4

Related Questions