Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to use ASP variables in Response.Redirect statement 1

Status
Not open for further replies.

caitlin

Technical User
Jun 21, 2002
15
US
Hi folks -

I'm drawing a complete blank - how do I use an ASP variable inside an ASP statement? I've forgotten the correct syntax and can't find it in my books.

Here's what I want to do:

<%Response.Redirect(&quot;teacher_classlist.asp?<%=varTeacherID%>&quot;)%>

varTeacherID is my variable, captured from a session. However, I can't use it in the above way because the syntax is wrong. Any ideas?

Thanks in advance!
-Caitlin in Tucson, AZ
 
<%Response.Redirect(&quot;teacher_classlist.asp?ID=<%varTeacherID%>&quot;)%>



TonyU.gif
 
no <% %> within <% %>
<% Response.Redirect &quot;teacher_classlist.asp?&quot; & varTeacherID %>

____________________________________________________
[sub]The most important part of your thread is the subject line.
Make it clear and about the topic so we can find it later for reference. Please!! faq333-3811[/sub]
onpnt2.gif
 
There are many ways, one like the one onpnt mentioned but I think its missing something.... Because if you are passing a parameter it has to have two parts, the name of the parameter, and the value, meaning :

<%
Response.Redirect &quot;urpage.asp?TeacherID=&quot; & varTeacherID
%>

meaning that afte submiting the page you request the value like this:

varTeacherID = Request(&quot;TeacherID&quot;)

The seond way is o do it in an html tag like this:

<a href=&quot;urpage.asp?TeacherID=<%=varTeacherID%>&quot;>Link Name</a>

both ways should work well, the second one is the best for hyber links..

Hope this is helpful,,
 
Thank you, bahakh!

The syntax rule appears to be:
1) use & in front of the variable, and
2) keep the variable outside of the quotes.

<%Response.Redirect &quot;teacherclass.asp?TeacherID=&quot; & variable %>

This works! Thanks very much -

Caitlin
 
The key syntax rules are that the &{/b] operator is used to concatenate strings together, that things inside quotes are strings, and that ASP only understands that it should substitute the value of a variable if you use the variable's name and not another string.
Code:
Dim Temperature     '<-- this is a variable
Temperature = &quot;Hot&quot; '<-- this puts a string, &quot;Hot&quot;, in the variable
Response.Write(&quot;Temperature&quot; & &quot;-&quot; & Temperature)
That last line puts together a string consisting of the letters &quot;Temperature&quot;, followed by the character &quot;-&quot;, followed by the value of the variable called Temperature, which at this point in the code is &quot;Hot&quot;. Then it writes it out (Response.Write) like this:
Code:
Temperature-Hot
 
Darned typos. That first line was supposed to say &quot;The key syntax rules are that the & operator is used...&quot;.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top