The Request.QueryString Collection is very similar to the Request.Form Collection and its formal definition is almost identical too:
The Request.QueryString Collection is very similar to the Request.Form Collection
When dealing with the Request object we are accessing information given or returned by the client. The QueryString access the data that follows up the URL. To start lets see a practical example. When starting to write my articles here to SWYNK.COM, I was faced with one dilemma: should I update my index page every time that an article is posted, or should I found an easy way of updating it automatically? I obviously choose the last one. Here’s how. Almost every link on my default.asp page is composed in this way:
(Verifica means verify and pagina means page in English)
The verifica.asp script will then check if the page indicated by pagina exists and if so it will redirect the visitor to it or else it will redirect it to a construction-warning page. The code is as follows:
— verifica.asp —
path = Server.MapPath(pagina)
Set fs = Server.CreateObject(“Scripting.FileSystemObject”)
If Not fs.FileExists(path) Then
— End of page —
Response.expires=0 tells proxies and browsers not to cache this page. The next line is the focus of this article. In it I retrieve the name of the page given by the link into variable pagina. Then I can use it to do the required processing. In particular I assign to path the real path to the file using Server.MapPath method and then test it existence using the Scripting.FileSystemObject. If the page exists (I’ve already posted the article) then Response.Redirect redirects the user to it. The ( not ready ) you can see on my index page is made in a similar manner.
Now back to Request.QueryString. This method of passing data can be used with two different objectives in mind, One is to make a flow control and the other is to pass data to a script from the client. We’ve seen the first and will now move on to the second. If you already readed my Request.Form article, you’ll notice that there are two forms on posting a form.
When given the value get to the attribute method, the browser will post all data to the server on the link request, rather than on http-headers. To access this information in ASP, you must use Request.QueryString collection in the same way of Request.Form. For more detailed information on how to do this, please read my article on using Request.Form, I’ve already covered most of the topics there. Now let’s review it in more detail.
Between 18 and 23
Between 24 and 45
Older than 45
This little Html form will be the basis to our discussions. Let’s say we have a script that will accept our form. And we want to retrieve the information given by the user to variables. Then our code will be:
You are aged
Select Case age_classe
Response.Write “under 18 years.”
Response.Write “between 19 and 23 years.”
Response.Write “between 24 and 45 years.”
Response.Write ” more than 45 years.”
All the considerations taken into account with the Request.Form collection can be made too to the Request.QueryString.
I want your feedback! Mail me!