|
 |
asptoday_discuss thread: Variables
Message #1 by "Tolga Akyay" <hacibumbala@h...> on Thu, 13 Dec 2001 08:05:55
|
|
Hi! I'm quite new in ASP. I want to define a variable when a link is
pressed and use it in the following page. How can I do it? Using the "?"
character in the link that I see in many web pages, how?
Message #2 by "Greg Jennings" <greg.jennings@t...> on Thu, 13 Dec 2001 16:01:52
|
|
Actually, you don't have to define the variable. You can build the URL of
the following page like this:
http://WEB_PAGE_ADDRESS?varname1=value1
where "varname1" is the name of the variable, and "value1" is the value
you want it to have. Then, in the ASP code for that following page, you
can use the Request.QueryString("varname1") to retrieve the value, like
this:
<%
dim local1
local1 = Request.QueryString("varname1")
%>
You can have multiple variables, too. Just separate the "varname=value"
pairs with the ampersand character (&).
> Hi! I'm quite new in ASP. I want to define a variable when a link is
> pressed and use it in the following page. How can I do it? Using the "?"
> character in the link that I see in many web pages, how?
Message #3 by "Pat Sullivan" <PSullivan@m...> on Thu, 13 Dec 2001 15:27:02 -0600
|
|
You don't need to use the Request.Querystring for this either, you could
do it like so
<%
Dim local1
local1 =3D Request("varname1")
%>
Also, say you are passing values generated in asp
<%
varname1 =3D 1
varname2 =3D 2
'generate link
link1 =3D "<a href=3D""page1.asp?varname1=3D" & varname1 &
"&varname2=3D" &
varname2 & """>Link</a>"
response.write(link1)
%>
or within html
<%=3Dlink1%>
or (not recomended, the more you go between html and asp the slower the
page)
<a
href=3D"page1.asp?varname1=3D<%=3Dvarname1%>&varname2=3D<%=3Dvarname2%>">
Link</a>
-----Original Message-----
From: Greg Jennings [mailto:greg.jennings@t...]
Sent: Thursday, December 13, 2001 10:02 AM
To: ASPToday Discuss
Subject: [asptoday_discuss] Re: Variables
Actually, you don't have to define the variable. You can build the URL
of
the following page like this:
http://WEB_PAGE_ADDRESS?varname1=3Dvalue1
where "varname1" is the name of the variable, and "value1" is the value
you want it to have. Then, in the ASP code for that following page, you
can use the Request.QueryString("varname1") to retrieve the value, like
this:
<%
dim local1
local1 =3D Request.QueryString("varname1")
%>
You can have multiple variables, too. Just separate the
"varname=3Dvalue"
pairs with the ampersand character (&).
> Hi! I'm quite new in ASP. I want to define a variable when a link is
> pressed and use it in the following page. How can I do it? Using the
"?"
> character in the link that I see in many web pages, how?
Message #4 by "Greg Jennings" <greg.jennings@t...> on Fri, 14 Dec 2001 03:21:59
|
|
That's true, you don't have to use the QueryString function. If you just
use Request("varname"), it will search variables in the URL *and*
variables from the form. However, if you know that the variable is being
passed through the URL, it would execute slightly faster and probably be
clearer to those that would have to maintain the code.
|
|
 |