Response.Write and Response.Redirect

S

Sehboo

On my ASP page, when I click a button, I want to do three things:

1. Check for some values.
2. Open a new window and pass some values as query string.
3. Redirect to some other page

Here is the code:

If (sServiceCenter = "*ALL") Then
sServiceCenter = "%"
End If

Dim scriptString As String = "<script language=""javascript"">"
scriptString = scriptString &
"mywindow=window.open('SBNIList.aspx?ServiceCenter=" & sServiceCenter
& _
"','_new','width=screen.width,height=screen.height,resizable=yes,status=no,toolbar=no,menubar=no,left=0,top=0,scrollbars=yes');</script>"

Response.Write(scriptString)
Response.Redirect("SBNIDone.aspx")

But it doesn't work. It just simply redirects and doesn't open the
new window. If I comment out the redirect line then it opens up the
new window.

Any idea?
 
H

Hans Kesting

Sehboo said:
On my ASP page, when I click a button, I want to do three things:

1. Check for some values.
2. Open a new window and pass some values as query string.
3. Redirect to some other page

Here is the code:

If (sServiceCenter = "*ALL") Then
sServiceCenter = "%"
End If

Dim scriptString As String = "<script language=""javascript"">"
scriptString = scriptString &
"mywindow=window.open('SBNIList.aspx?ServiceCenter=" & sServiceCenter
& _
"','_new','width=screen.width,height=screen.height,resizable=yes,status=no,t
oolbar=no said:
Response.Write(scriptString)
Response.Redirect("SBNIDone.aspx")

But it doesn't work. It just simply redirects and doesn't open the
new window. If I comment out the redirect line then it opens up the
new window.

Any idea?

You can't both send output and redirect. An HTTP Redirect is like saying
"there is no
content here, try there", so the browser should ignore anything that was
sent anyway.
Maybe ASP.Net also any response text that was generated.

Solution: put the redirect in with the script that you were already sending.

Hans Kesting
 
C

Craig

Hans is mostly right, but there's a way to do what you're wanting... You
can't use Response.Redirect, instead you need to use the HTML REFRESH
metatag because it allows the page to actually display and then redirect
after a specified time period.

So, use Response.Write (or whatever method you want) write out to the new
page whatever you want to display and add the refresh metatag with a 10
second delay or whatever, you're set.
 
S

Sehboo

Actually I found out the solution after I posted this question:

Instead of Response.Redirect, I needed to do server.transfer. It works now.

Thanks for the responses though.
 

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,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top