how does Request.QueryString work?
Asked Answered
O

5

23

I have a code example like this :

 location.href = location.href + "/Edit?pID=" + hTable.getObj().ID; ; //aspx    
 parID = Request.QueryString["pID"]; //c#

it works, my question is - how ? what is the logic ? thanks :)

Ortensia answered 21/8, 2013 at 15:2 Comment(3)
i guess you just have to split the url using ? as split param, then split it using =, finally populate a dictionary using the second split item. It a little more complicated that that since I don't know how ? and = are encoded, but that's the rough logic I thinkIndividual
Wait, are you asking the usage or how it work behind the scene?Individual
Fabio,behind the scene.Ortensia
R
32

The HttpRequest class represents the request made to the server and has various properties associated with it, such as QueryString.

The ASP.NET run-time parses a request to the server and populates this information for you.

Read HttpRequest Properties for a list of all the potential properties that get populated on you behalf by ASP.NET.

Note: not all properties will be populated, for instance if your request has no query string, then the QueryString will be null/empty. So you should check to see if what you expect to be in the query string is actually there before using it like this:

if (!String.IsNullOrEmpty(Request.QueryString["pID"]))
{
    // Query string value is there so now use it
    int thePID = Convert.ToInt32(Request.QueryString["pID"]);
}
Respective answered 21/8, 2013 at 15:5 Comment(0)
H
8

A query string is an array of parameters sent to a web page.

This url: http://page.asp?x=1&y=hello

Request.QueryString[0] is the same as 
Request.QueryString["x"] and holds a string value "1"

Request.QueryString[1] is the same as 
Request.QueryString["y"] and holds a string value "hello"
Hoop answered 21/8, 2013 at 15:20 Comment(2)
the only way to pass QueryString parameters is by using (?) - sign ?Ortensia
Request.Form[] is another collection that holds form field inputs. But QueryString is pretty much the product of the "?" URL syntax.Hoop
M
5

The Request object is the entire request sent out to some server. This object comes with a QueryString dictionary that is everything after '?' in the URL.

Not sure exactly what you were looking for in an answer, but check out http://en.wikipedia.org/wiki/Query_string

Microfiche answered 21/8, 2013 at 15:9 Comment(0)
S
5
Request.QueryString["pID"];

Here Request is a object that retrieves the values that the client browser passed to the server during an HTTP request and QueryString is a collection is used to retrieve the variable values in the HTTP query string.

READ MORE@ http://msdn.microsoft.com/en-us/library/ms524784(v=vs.90).aspx

Shortage answered 21/8, 2013 at 15:11 Comment(0)
P
0

The QueryString collection is used to retrieve the variable values in the HTTP query string.

The HTTP query string is specified by the values following the question mark (?), like this:

Link with a query string

The line above generates a variable named txt with the value "this is a query string test".

Query strings are also generated by form submission, or by a user typing a query into the address bar of the browser.

And see this sample : http://www.codeproject.com/Articles/5876/Passing-variables-between-pages-using-QueryString

refer this : http://www.dotnetperls.com/querystring

you can collect More details in google .

Pickax answered 21/8, 2013 at 15:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.