Response.Write and Response.Redirect

Discussion in 'ASP .Net' started by Sehboo, Dec 9, 2003.

  1. Sehboo

    Sehboo Guest

    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?
    Sehboo, Dec 9, 2003
    #1
    1. Advertising

  2. Sehboo

    Hans Kesting Guest

    "Sehboo" <> wrote in message
    news:...
    > 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,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?


    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
    Hans Kesting, Dec 9, 2003
    #2
    1. Advertising

  3. Sehboo

    Craig Guest

    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.


    "Hans Kesting" <> wrote in message
    news:...
    >
    > "Sehboo" <> wrote in message
    > news:...
    > > 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,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?

    >
    > 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
    >
    >
    Craig, Dec 9, 2003
    #3
  4. Sehboo

    Sehboo Guest

    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.

    "Craig" <> wrote in message news:<#>...
    > 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.
    >
    >
    > "Hans Kesting" <> wrote in message
    > news:...
    > >
    > > "Sehboo" <> wrote in message
    > > news:...
    > > > 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,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?

    > >
    > > 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
    > >
    > >
    Sehboo, Dec 10, 2003
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Charles A. Lackman
    Replies:
    2
    Views:
    7,972
    Charles A. Lackman
    Jan 11, 2006
  2. Matthew Wieder

    Response.Write and Response.Redirect

    Matthew Wieder, Jul 17, 2003, in forum: ASP .Net
    Replies:
    4
    Views:
    675
    Kevin Spencer
    Jul 17, 2003
  3. =?Utf-8?B?VHJveQ==?=

    Response.redirect does not redirect from .aspx page

    =?Utf-8?B?VHJveQ==?=, Oct 18, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    5,214
    Srowe1975
    Oct 15, 2008
  4. slawekg

    Response.Write and Response.Redirect

    slawekg, Jun 21, 2007, in forum: ASP .Net
    Replies:
    3
    Views:
    365
    Alexey Smirnov
    Jun 21, 2007
  5. Sal
    Replies:
    1
    Views:
    374
Loading...

Share This Page