What's the easiest / standard way to retrieve the GET (in URL) variables passed to a .aspx (VB) page?
Asked
Active
Viewed 7.4k times
23
-
Here is an example from SO on looping through the GET postback values. [http://stackoverflow.com/questions/562943/looping-through-a-request-querystring-in-vb-net](http://stackoverflow.com/questions/562943/looping-through-a-request-querystring-in-vb-net) – Zachary Jun 23 '09 at 16:08
3 Answers
50
You can use the following:
Example URL: http://www.whatever.com?hello=goodbye&goodbye=hello
string value = Request.QueryString("hello");
Value will be goodbye
or
foreach(string key in Request.QueryString)
{
Response.write(Request.QueryString(key))
}

Paul B.
- 2,394
- 27
- 47

Jonathan Mayhak
- 12,376
- 3
- 21
- 17
-
-
1@ClayNichols same here. `Request.QueryString["hello"]` doesn't work. `Request.QueryString("hello")` does. – tresf Dec 22 '16 at 16:09
-
I took the liberty to change [ ] to ( ). The latter is VB.NET syntax which the question is about. – Paul B. Jan 16 '20 at 09:18
-
Dec 2020 and this is not working for me. Just getting a blank line when trying to log value. Should this still work? – Cole Perry Dec 14 '20 at 14:44
1
if you have a path :
www.stackoverEvan.com/question/directory-lookup.asp?name=Evan&age=16
If you do :
Hi , <%= Request.QueryString("name") %>.
Your age is <%= Request.QueryString("age") %>.
Output :
Welcome, Evan. Your age is 16
But as your specifying it's in VB the optimal way would be like :
Path :
http://localhost/script/directory/NAMES.ASP?Q=Evan&Q=Bhops
Code :
--- Names.asp ---
<%
For Each item In Request.QueryString("Q")
Response.Write Request.QueryString("Q")(item) & "<BR>"
Next
%>
Output :
Evan
Bhops