What’s \nNext?<\/a>]<\/p>\n <\/p>\n
Request.QueryString: \nPassing Information Along<\/h2>\n <\/p>\n
Now that you know how to \npass information from one page to another using a Session Variable, let’s talk \nabout a different way to pass information along.<\/p>\n
<\/p>\n
Request.QueryString<\/b> \nis used to retrieve information directly from the URL. Let’s take a real-life \nsituation and see how Request.QueryString<\/b> works:<\/p>\n
<\/p>\n
Let’s say you have a \nwebsite that has several different game reviews on it. On your home page you \nhave 6 different links to different reviews. Instead of creating 6 separate \npages, 1 for each review, you decide that you are going to use a single ASP page \nto display the reviews. The only problem is knowing which review to display.<\/p>\n
<\/p>\n
The solution that you \ncome up with uses Request.QueryString<\/b>. You determine that the easiest way \nto let your review display page know what review to display is to send the \nuser’s selection through the URL.<\/p>\n
<\/p>\n
You first create your 6 \ndifferent review links on your home page that look something like this:<\/p>\n
<\/p>\n
<A href="reviews.asp?reviewid=game1">Review \n1<\/A><\/p>\n
<\/p>\n
There is really nothing \nspecial about how the link is created, it’s just standard HTML. The special part \nis how you construct the URL. As you can see, the first part of the link is \nquite normal, just the name of the page that we want to go to. Then there is the \nquestion mark. The question mark is used to differentiate between the page path \nand the information that we are passing along. Next is the identifier for our \ninformation, "gameid". Each item that you pass through a URL must have it’s own \nunique identifier within the URL in order for Request.QueryString<\/b> to do \nits job. Finally, we set our unique identifier equal to whatever information we \nwant to pass along, which is "game1" in this case.<\/p>\n
<\/p>\n
So, what if I want to \nsend more than one piece of information via a URL?<\/p>\n
<\/p>\n
You can send as much \ninformation as you like by using the ampersand to connect the pieces. Here’s an \nexample:<\/p>\n
<\/p>\n
<A href="link.asp?item1=yes&item2=no">Link<\/A><\/p>\n
<\/p>\n
Now that you understand \nhow to send the information in a URL, let’s take a look out getting the \ninformation out using Request.QueryString<\/b>. In order to best demonstrate \nhow Request.QueryString<\/b> works I’ll give you the code for the game review \nexample we started above:<\/p>\n
<\/p>\n
<% Option Explicit %><\/p>\n
…<\/p>\n
<% Select Case \nRequest.QueryString<\/b>("gameid") %><\/p>\n
<% \nCase "game1" %><\/p>\n
\n<% Response.Write "This is the game 1 review …" %><\/p>\n
<% \nCase "game2" %><\/p>\n
\n<% Response.Write "This is the game 2 review …" %><\/p>\n
<% \nCase "game3" %><\/p>\n
\n<% Response.Write "This is the game 3 review …" %><\/p>\n
<% \nCase "game4" %><\/p>\n
\n<% Response.Write "This is the game 4 review …" %><\/p>\n
<% \nCase "game5" %><\/p>\n
\n<% Response.Write "This is the game 5 review …" %><\/p>\n
<% \nCase "game6" %><\/p>\n
\n<% Response.Write "This is the game 6 review …" %><\/p>\n
<% End Select %><\/p>\n
<\/p>\n
We use a Case statement \nto determine which review needs to be displayed. You’ll notice the \nRequest.QueryString<\/b> in the beginning of the Case statement. To retrieve a \nvalue from a URL, all you need to know is the unique identifier that is being \nused. In our case, the only unique identifier that we are using is "gameid".<\/p>\n
<\/p>\n
What happens if I \nmisspell my unique identifier or forget to add it to the URL?<\/p>\n
<\/p>\n
If \nRequest.QueryString<\/b> doesn’t find the unique identifier that you are looking \nfor it will simply return an empty string value, i.e. "".<\/p>\n
<\/p>\n
Though it is a very \nsimple process to send information from page to page via the URL, there are a \nfew things you need to be aware of:<\/p>\n
\n\nAny information sent via \na URL is not<\/i> secure. Whatever you do, don’t ever pass credit card numbers \nor any other sensitive information along in a URL.<\/p>\n<\/li>\n\nIt’s not like a Session \nVariable. Session Variables keep their value from page to page no matter how \nmany pages the user jumps around to. With Request.QueryString<\/b>, the value \nmust be passed in the URL each time you move from one page to another.<\/p>\n<\/li>\n\nURL’s are very temper \nmental about the way they are structured. If you are unsure whether the URL that \nyou are using is compliant, you can use a spiffy little function called \nServer.URLencode<\/b>. (See Tip)<\/p>\n<\/li>\n<\/ul>\n\n
<\/p>\n\n\nTip<\/b><\/p>\n There is a great built-in ASP feature called \n Server.URLencode<\/b>. It takes any string you give it and replaces all \n of the illegal characters with URL compliant translations. You use \n Server.URLencode<\/b> like this:<\/p>\n
Server.URLencode<\/b>("My Name")<\/p>\n
The function then translates the information that you give it and spits \n out the appropriately translated string for a URL:<\/p>\n
My+Name<\/p>\n
It is intended to only translate strings within a URL and not the \n entire URL. Whatever you do, don’t give Server.URLencode<\/b> an entire \n URL like this:<\/p>\n
Server.URLencode<\/b>("test.asp?n=My Name")<\/p>\n
Or you will get a messed up result like this:<\/p>\n
test%2Easp%3Fn%3DMy+Name<\/td>\n<\/tr>\n<\/table>\n
<\/center>\n<\/div>\n
\n<< Previous<\/a> | Next<\/a> >><\/p>\n
<\/p>\n
<\/TD><\/TABLE><\/CENTER> \n<\/TD><\/p>\n","protected":false},"excerpt":{"rendered":"
ASP Primer: Making a Request ASP Primer: Making a Request by Curtis Dicken Use these bookmarks to jump around the tutorial: [Request.Cookies: Getting Stuff Out of a Cookie<\/p>\n","protected":false},"author":57,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[30630],"tags":[],"b2b_audience":[29],"b2b_industry":[],"b2b_product":[],"acf":[],"yoast_head":"\n
ASP Primer: Making a Request | HTML Goodies<\/title>\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\t \n