#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Posts
    20
    Rep Power
    0

    Redirect not working...easy question?


    I'm building my first asp application and all I want to do is have the form either write "try again" or navigate to a particular page.

    You can see what I have so far at:
    http://www.designdevelopdeliver.com/...ntier/test.asp

    Checking the second radio button works fine, but checking the first one gives an error when it should just redirect the page??

    TIA
  2. #2
  3. No Profile Picture
    Overly white
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Location
    Fresno, CA
    Posts
    83
    Rep Power
    12
    Code:
    <% if Request("rad1")= "" then '*this if is unneeded*
    else
    If Request.QueryString("rad1") = "radio1" Then
    Response.Redirect("test2.asp")
    else
    Response.Write "...Try Again..."
    End If
    End If
    %>
    The probelm is your trying to redirect to another page AFTER the current page is already being written. You have to redirect BEFORE the page is written. What you should do is move all that code top the top of the page.

    Code:
    <%
    If Request.QueryString("rad1") = "radio1" Then
      Response.Redirect("test2.asp")
    Else
      strResponse = "...Try Again..."
    End if
    %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    
    <body>
    <p><%If Len(strResponse) <> 0 then Reponse.write(strresposne) %>... <!-- the rest of the document goes here. -->
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Posts
    20
    Rep Power
    0
    YES!! That did it, thanks.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2001
    Location
    NJ
    Posts
    428
    Rep Power
    16
    Or you can just set the response.buffer to true and then you can redirect whenever you want. IN IIS 5.0 that is the default, but earlier versions you have to do it at the top of each page:

    response.buffer = true

    that's it
  8. #5
  9. No Profile Picture
    Overly white
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Location
    Fresno, CA
    Posts
    83
    Rep Power
    12
    Thanks for that tip imbrokn I wasn't aware of that.

IMN logo majestic logo threadwatch logo seochat tools logo