forcing a new browser window

G

G Dean Blake

in my aspx app I am writing a stream that works fine but it replaces what is
in the client browser window. The code is as follows:
..
..
HttpContext.Current.Response.ClearHeaders()
HttpContext.Current.Response.ClearContent()
HttpContext.Current.Response.ContentType = "application/pdf"
Dim myBuffer(MyStream.Length) As Byte
MyStream.Read(myBuffer, 0, CType(MyStream.Length, Integer))
HttpContext.Current.Response.BinaryWrite(myBuffer)
HttpContext.Current.Response.End()

Is there any way I can force this to write to a new browser window?
TIA,
G
 
N

Norman Yuan

You can only open a new browser window through client end script, server
code cannot and should not be allowed to do that.. That is, only user's
action on the client browser can bring up a new browser window. If server
code could do that, a bad guy would be easily write a simple page a attract
unsuspicious users and then keep popping up thousands of new windows until
the computer dies.
 
G

G Dean Blake

Well,....
for instance you can set the Target property for any hyperlink to "_blank"
and it will trigger a new browser window when the hyperlink is executed.
Also, in the dataGrid property window you can set "_blank" in the target
dropdown and the same thing happens.

There is certainly no user action in either of these examples.
 
E

Eliyahu Goldin

Not sure what you mean by the target dropdown in the dataGrid property
window , but in the case of a hyperlink clicking the link is certainly a
user action. You can emit a javascript statement like window.open,
showModelDialog etc.

Eliyahu
 
G

G Dean Blake

I'm not up on Javascript. How would I emit a statement like Window.open?
For instance when doing a response.redirect to a page is there a way somehow
to open a new window?
Thanks,
G
 
N

Norman Yuan

When the page is loaded the first time, you do:

private void Page_Load(....)
{
if (!Page.IsPostBack)
{
btn1.Attributes.Add("onlick",

"window.open('http://myServer//page1.aspx?param1=xxx&param2=yyyy',toolbar=0,
......); return false;");
}
else
{
...
}
}

after the page is loaded, if due to some user action, the URL for the new
window need to be changed, say, afer user clicking btn2, the underline
javascript for btn1 needs to be changed to open a different page, then you
need reattach the client javascript, so that btn1 now will open a different
page in new window:

private void btn2_Click(...)
{
try
{
btn1.Attributes.Remove("onclick")
}
catch{}

btn1.Attributes.Add("onlick",

"window.open('http://myServer//page2.aspx?param1=aaaa&param2=bbbb',toolbar=0
,.....); return false;");

}

Note, at the end of "window.open()", I add "return false;", so that clicking
btn1 will not cause unnecessary postback.
 
G

G Dean Blake

If I understand this right when this page loads (lets call it mainpage) it
provides a button that will open another page (page1.aspx) to open in a new
window? I want the mainpage to open in a new window.
G
 

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

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
SterlingLa
Top