Codefixer - ASP tutorials, resources and software
New MS SQL 2008 Available – DiscountASP.NET
Home   Articles   Resources   ASP directory   ASP Tutorials   Code Snippets   ASP Applications   Forum
Sunday 7 September
MembersPro PayPal - ASP Membership software

New MS SQL 2008 Available – DiscountASP.NET


ASP Partner ASP Partner ASP Partner more partners...

The Querystring

Have you ever seen a webpage that doesn't look like the standard www.codefixer.com you type into the address bar. Maybe something like:

www.resume-samples.com/resume.asp?resume=lawyer

You'll notice the question mark attached on the end with a name/value pair. The name in this case is resume and it's value lawyer.

All this is really doing is using the querystring in ASP to pass information to a page and the ASP script within it. In the above case the page displayed may now know to run code to show a lawyer's resume rather than a doctor's because of the value passed.

The page 'choice.asp' displays its background color equal to the value of choice passed in the querystring. Choice.asp with a blue background and choice.asp with a
red background.

ASP Querystring


ASP Querystring

Create a file called 'querystring.asp' and paste the code below into it. Let me explain what this code will do. There will be 3 hyperlinks <a href....> when you click on one of these, all the links will take you to the same page though through the querystring you are passing a value .. and that value will hold your color. Once that link has been clicked and the querystring holds a value ( Request.querystring("value") <> "" ) then write out the value of request.querystring("color") which will we be the color you chose.

Just note that in the following example that the links and the values in the querystring are going to the same page (we are using only one page). Therefore if the querystring doesn't hold a value then display all the links otherwise if it does hold a value write out that value as the fav color.

<%@ Language="VBscript" %>
<html>
<head>
<title>Querystring color</title>
</head>

<body>
<%
If Request.querystring("color") <> "" Then
Response.write "You picked " & Request.querystring("color") & " as the color."
Else
%>

What is your favorite colour?

<ul>
<li><a href="querystring.asp?color=blue">blue</a></li>
<li><a href="querystring.asp?color=green">green</a></li>
<li><a href="querystring.asp?color=red">red</a></li>
</ul>
<%
End if
%>

</body>
</html>

Note you may want to send more than one value through the querystring. Below is how a link to the page 'querystring.asp' would send the values of name and sex.

<a href="querystring.asp?name=michael&sex=male">link</a>

LinksPro - Directory  and Link  Management Software




ASP.NET 3.5/2.0 Web Hosting: 3 Months FREE – Click Here!




About | Contact | Advertise | Feedback | Hire Us | Link

Site developed by Michael Wall - Web Design Belfast N.Ireland.
Copyright © 2000-2008. All rights reserved.

Do you intend to move to ASP.NET or have you already?
Yes will do
Have done
ASP does fine
Not a priority


Directory Software