Introduction
Sometimes we pass values from one page to other page in URL. QueryString is main object which helps to do the same.
Using code
QueryString - As per W3(WWW), a query string is the part of a uniform resource locator (URL)
containing data. The QueryString collection is used to retrieve the variable values in the HTTP query string. It is also considered as Client-Side state management technique in ASP.NET. As a security, always encode header data or user input before using it. A method for encoding data is Server.HTMLEncode() and for decode use Server.HTMLDecode().
The QueryString is specified by the values following the question mark (?), like this:
http://localhost:1997/WebForm1.aspx?id=10&name=manas
How to get all Keys and Values
Option 1: Using AllKeys properties
- foreach (var cookieKey in Request.QueryString.AllKeys)
- {
- Response.Write("Key: " + cookieKey + ", Value:" + Request.QueryString[cookieKey]);
- }
Option 2: Using no of QueryString Count
- for (int idx = 0; idx < Request.QueryString.Count; idx++)
- {
- Response.Write("Value:" + Request.QueryString[idx]);
- }
Option 3: Using Keys Count

Join the conversation! Your thoughts help the community grow.