how to open a new browser windows using asp.net code?

  • Thread starter Thread starter David
  • Start date Start date
D

David

Hi

I don't want to use javascript to open a new window because I want to use
server side code which gives me more control. I think I can not use
response.redirect to open a new window and keep the current window.
Is there any way to do it?

Thank you!

David
 
You can not force a client to open a new browser window without having some
client side script (javascript or vbscript) from the server. So the answer
to your question is no.

What more control do you think you would have from the server anyway?

Also, you have no control from the server side, so client side will give you
much more control.

bill
 
Hi Bill
Thanks a lot.

My problem is I want to execute some server side code first (checking the
validity of passing values), then open a new window when the user click the
open new window button.
 
David,

The simple solution is to combine the both.

Here's an example scenario.

Create a literal control call litJavaScript on your webform.

In your event that processes your data server-side perform your validation
(or whatever you're doing). Then
add the following:

String js = "<script
langauage='javascript'>window.open('url.aspx')</script>";
litJavaScript.Text = js;

When the page renders the javascript will run and execute your open window
call.

Good luck
Bryce
 
David,

Check out the RegisterStartupScriptBlock/RegisterClientScriptBlock functions:

e.g.
dim myScript as string = "<script language=javascript>alert('MyMessage');</script>";
Page.RegisterClientScriptBlock("MyScript", myScript)

enter this code in your event

Greetings

Daniel
 
Back
Top