简体   繁体   中英

Using IF Then and Response.Redirect in ASP

So I have three pages. The first page I define a link with a string

<a href="divProgLog.asp?div=Division 2">

The second page I grab the string and assign a variable

<%  divrec = request.QueryString("div")%>

The third page processes everything. I would like for the process to be if the string is equaled to Division 2 the user will be redirected to another page. I'm using the following code but its not working

divstring = "divisions.asp?div=" & divrec & "&Last_Name=" & Last_Name & "&First_Name="    &First_Name
divstring2 = "divisions2.asp?div=" & divrec & "&Last_Name=" & Last_Name & "&First_Name=" &First_Name
if divrec = Division 2 then
Response.Redirect divstring2
else
Response.Redirect divstring
end if

I didn't use VB.Net for a long time, but try this:

divstring = "divisions.asp?div=" & divrec & "&Last_Name=" & Last_Name & "&First_Name="    &First_Name
divstring2 = "divisions2.asp?div=" & divrec & "&Last_Name=" & Last_Name & "&First_Name=" &First_Name
If divrec = "Division 2" Then
Response.Redirect(divstring2)
Else
Response.Redirect(divstring)
End If

Your page shouldn't be compilable by the way.

Do not forget to use an upper case for If , Then and End If .

Also Division 2 is a string so you have to surround it with double-quotes.

Response.Redirect is a method so parameters are specified between parenthesis.

I think you should try taking the space out of Division 2 ID and rename it to Division2.

ie <a href="divProgLog.asp?div=Division2">

Then modify your code to be

If divrec = "Division2" Then
    Response.Redirect(divstring2)
Else
    Response.Redirect(divstring)
End if

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM