Go to DotNetFunda.com
 Online : 671 |  Welcome, Guest!   Login
 
Home > Articles > ASP.NET > How to work with QueryString?

Submit Article | Articles Home | Search Articles |

How to work with QueryString?

red flag  Posted on: 7/30/2010 5:19:31 PM by Ganeshji | Views: 814 | Category: ASP.NET | Level: Beginner


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


If you like this article, subscribe to our RSS Feed. You can also subscribe via email to our Interview Questions, Codes and Forums section.

Found interesting? Add this to:

| More



Please Sign In to vote for this post.

 
Latest post(s) from Ganeshji

Latest Articles
Experience:1 year(s)
Home page:
Member since:Saturday, July 24, 2010
Level:Starter
Status: [Member]
Biography:

Submit Article

About Us | The Team | Advertise | Contact Us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you found plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 9/7/2010 12:13:46 AM