How to work with QueryString?

Ganeshji
Posted by in ASP.NET category on for Beginner level | Views : 33188 red flag
Rating: 4.5 out of 5  
 2 vote(s)

Here i have tried to put some explanation about Query String with some examples.

Introduction


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:

http://www.gmail.com?a=madurga&b=ganeshji.

Let me specify in details:

http://www.gmail. 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.


Disadvantage:

  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.

Syntax


Request.QueryString(variable)[(index)|.Count]



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


Default.aspx



Default.aspx.cs


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




Default2.aspx


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





Output




Default3.aspx.cs

QueryString variables can also be accessed in this way.






Output


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.





Conclusion



I tried to explain this control in details. Plz let me know all of yours feedback.

Reference

  1. http://www.codeproject.com/KB/aspnet/QueryString .aspx
  2. http://dotnet.dzone .com/news/aspnet-query-strings-client-si

Page copy protected against web site content infringement by Copyscape

About the Author

Ganeshji
Full Name: Zinnia Sarkar
Member Level:
Member Status: Member
Member Since: 7/24/2010 12:50:40 PM
Country: India
Regards, Ganeshji


Login to vote for this post.

Comments or Responses

Posted by: Akiii on: 6/7/2011 | Points: 25
hi,

It helped me in understand the concept...
Keep posting...

Thanks and Regards
Akiii
Posted by: Ganeshji on: 6/8/2011 | Points: 25
Thnx Akii!
Posted by: Vinay13mar on: 10/25/2012 | Points: 25

Login to post response

Comment using Facebook(Author doesn't get notification)