Query String in ASP.Net, ASP.Net QueryString Usage

 Query string is used to Pass the values or information form one page to another page.

passing variables content between pages ASP.NET gives us several choices. One choice is using QueryString property of Request Object. When surfing internet you should have seen weird internet address such as one below.

http://24x7aspnet.blogspot.com/QueryString.aspx?name=Rajiv&lastName=Kumar

The Request.QueryString collection is a NameValueCollection internally. QueryString is implemented as a property getter for an internal NameValueCollection. The NameValueCollection is a specialized collection that has a somewhat unusual implementation. MSDN describes it as a "collection of associated String keys and String values that can be accessed either with the key or with the index."

A typical URL containing a query string is as follows:
http://server/path/program?query_string

When a server receives a request for such a page, it runs a program (if configured to do so), passing the query_string unchanged to the program. The question mark is used as a separator and is not part of the query string.
A link in a web page may have a URL that contains a query string. However, the main use of query strings is to contain the content of an HTML form, also known as web form. In particular, when a form containing the fields field1, field2, field3 is submitted, the content of the fields is encoded as a query string as follows:
field1=value1&field2=value2&field3=value3...
  • The query string is composed of a series of field-value pairs.
  • The field-value pairs are each separated by an equal sign.
  • The series of pairs is separated by the ampersand, '&' or semicolon, ';'.
For each field of the form, the query string contains a pair field=value. Web forms may include fields that are not visible to the user; these fields are included in the query string when the form is submitted.
This 'name then equal sign then value then ampersand or semicolon' convention is a W3C recommendation. W3C recommends that all web servers support semicolon separators in the place of ampersand separators.
Technically, the form content is only encoded as a query string when the form submission method is GET. The same encoding is used by default when the submission method is POST, but the result is not sent as a query string, that is, is not added to the action URL of the form. Rather, the string is sent as the body of the request.
Related Topic:



Tags: , , , ,
Hot on Web:


About author