open new browser window from server

  • Thread starter Thread starter Wardeaux
  • Start date Start date
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
 
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.
 
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
 
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.
 
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.
 
Back
Top