123ArticleOnline Logo
Welcome to 123ArticleOnline.com!
ALL >> Computers >> View Article

How To Use The Querystring In Asp

Profile Picture
By Author: Sven Vdhrison
Total Articles: 3
Comment this article
Facebook ShareTwitter ShareGoogle+ ShareTwitter Share

This article tells you how to pass variables to an ASP page using the QueryString, and how to access them from that page.
Level: Beginner Introduction
Have you ever seen a URL which looked like "www.example.com/page.asp?mode=1&style=red"? Well, this page is being passed variables and their values through the QueryString, here the variables "mode" and "style" are being passed, with values "1" and "red" respectively. The question mark indicates the start of the query string and the ampersand, &, symbol seperates variable=value assignments.
The page is then able to read these variables and react according to them, for example to display them to the user. Passing a QueryString to a page
There are two ways to pass a QueryString to a page, the first is to enter it manually, for example:
<a href="page.asp?mode=1">Mode 1</a>
The above HTML creates a link to a page passing the variable mode with the value "1". An alternative, and perhaps more useful, way is to use HTML forms. The main thing to remember with ...
... forms is that you need to use the GET method to send information via the QueryString, for example:
<form method="GET" action="page.asp">
Please enter your name: <input type="text" name="username" />
<input type="submit" value="submit" />
</form>
This code displays a simple HTML form with a text box and a submit button. When the user enters their name and presses submit, the information in the name box is passed to a page called "page.asp" (specified in the form's action attribute) via the QueryString. So, if I entered "mooseh" and pressed submit, the form will call page.asp?username=mooseh. Remember that "username" was what we entered as the text input's name attribute. Accessing a QueryString element in ASP
In ASP, all the information passed via the QueryString is held in the Request.QueryString collection. To access an item, type Request.QueryString("varName"), where varName is the name of the variable in the QueryString. To demonstrate, let's create page.asp to process the information from the form above:
<%@language="VBScript"%>
<% If Request.QueryString("username") <> "" Then
Response.Write "Hello, " & Request.QueryString("username")
Else
Response.Write "You did not enter a name."
End If
%>
So now, me typing in mooseh and pressing submit will generate the reply "Hello, mooseh". Listing the contents of Request.QueryString
Should you wish to find out everything that's in the QueryString, you can do so with the following code which displays the variables next to their values in a table: <%@language="VBScript"%>
<table border="1">
<tr><th>variable</th> <th>value</th></tr>
<%
Dim variable
For Each variable in Request.QueryString
Response.Write "<tr><td>" & variable & "</td>"
Response.Write "<td>" & Request.QueryString(variable) & "</td></tr>"
Next
%>
</table> Conclusion
This article showed you how to pass information between pages with the QueryString, and a use which allows you to add some increased interactivity. There are a lot of other uses, for example selecting which section of a site to display based on a variable in the QueryString, and processing form data.
vdhri.net is a website dedicated to providing free lessons and tutorials in many programming languages.

Total Views: 77Word Count: 474See All articles From Author

Add Comment

Computers Articles

1. Managed Soc Services For It Companies
Author: Devendra singh

2. Ai Data Protection Compliance: Best Practices For Secure Business Operations
Author: Devendra singh

3. Privileged Access Management (pam): Strengthening Enterprise Security And Access Control
Author: Umangp

4. Qlikview Tutorial For Data Analytics: Create Interactive Dashboards And Reports
Author: Tech Point

5. Enterprise Email Security: Strengthening Protection Against Evolving Email Threats
Author: Umangp

6. Access Management Market Trends: Future Growth And Emerging Technologies
Author: Umangp

7. Mobile App Scraping
Author: MObile app scraping

8. Master Data Management Solutions: Driving Data Quality Through Ai And Cloud
Author: Umangp

9. Digital Marketing Analytics Platforms: Key Trends, Benefits, And Future Market Outlook
Author: Umangp

10. Ai Governance Market: Trends Driving Responsible Ai Adoption
Author: Umangp

11. Spark Matrix™: Access Management
Author: Umangp

12. The Future Of Digital Content In India: Why Photo Sharing And Cloud Storage Are Converging
Author: vijaylaxmi soni

13. Looking For German Industrial Chemicals Suppliers? Choose The Right Partner With Roteschemie
Author: Roteschemie

14. Ai Augmented Software Development: Ai-driven Coding, Automated Testing, Risk Prediction, Team Collaboration, Productivity, And Market Outlook
Author: Umangp

15. Kiosk Systems In Hyderabad For Modern Businesses
Author: pbs

Login To Account
Login Email:
Password:
Forgot Password?
New User?
Sign Up Newsletter
Email Address: