open new browser window from server

W

Wardeaux

I can't find a way to open a new browser window from my codebehind.

1) My page does a postback to the server.
2) On server I evaluate whether to return to existing page or leave existing
page displayed and open new window with different page

Seems easy enough, I've just not found the key element to make this happen.
Anyone found the solution??

MTIA
wardeaux
 
R

Raterus

You won't be able to do that from the server. You'll have to do this on the client-side with javascript. Write it out to the page somewhere on the response.
 
C

Craig Deelsnyder

Wardeaux said:
I can't find a way to open a new browser window from my codebehind.

1) My page does a postback to the server.
2) On server I evaluate whether to return to existing page or leave existing
page displayed and open new window with different page

Seems easy enough, I've just not found the key element to make this happen.
Anyone found the solution??

MTIA
wardeaux

You have to insert some Javascript to popup the new window when loaded,
since the server has no concept of a 'client window'.

Here's an example of how to inject the script, replace the alert with
whatever you're trying to do.

http://searchvb.techtarget.com/vsnetATEAnswers/0,293820,sid8_gci882223_tax293672,00.html
 
W

Wardeaux

Suresh,
thanks! Any way to keep that script from running EVERY time the page is
loaded like when you hit either the "Back" or "Refresh" button?
wardeaux

Suresh said:
Use RegisterStartupScript method in your codebehind to register a client
side window.open javascript call.
It will be rendered as the page reloads and when the browser encounters
the javascript code it will execute it.
 
G

Guest

Refresh will cause a page load. Since the window.open is registered on postback the script shouldn't be registered on page load.

As for when the user presses the browser back button?
That's a drawback of using RegisterStartupScript method.

Suresh.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top