Thursday, 6 June 2013

How to work with QueryString


In Web development, passing of parameters from one page to another is an essential part. By using QueryString, one can easily transmit data from one page to another. These QueryStrings  are simply the data that is appended to the end of a page URL. The user can see the values which the query string holds without using special operations like ViewSource. An example of QueryString  is:
Let me specify in details: com is the URL here
? is the separator between the URL and the QueryString variables.
a  and b are the QueryString variables, the value of which are to be sent to the next page.


  1. If the number of parameters increases, then it becomes cumbersome and often difficult to maintain code using QueryString.
  2. Some browsers and client devices impose a 2083-character limit on the length of the URL.



Parameter List

1.     Variable - It is a mandatory parameter. It is used to retrieve the value of the variable used in the HTTP query string.

2.     Index - It is an optional parameter. Specifies one value at a time out of multiple values for a variable.

     Ex: From 1 to Request.QueryString (variable).Count



Here, i have redirected the page to the Defualt2.aspx, and the QueryString variables are also carrying there respective data along with them.


In this page, we have simply accessed the QueryString variables and concatenated them to the Label1.



QueryString variables can also be accessed in this way.


For accessing multiple values of QueryString, you may use For loop. If you want to use For loop for multiple QueryString values, then you should do use the following sample.

No comments:

Post a Comment