Assume we need to pass certain Variable content between html or aspx pages, often the Request object of QueryString is used. QueryStrings are combination of {key=value} pairs joined by ‘&’ and added to the html or aspx page Url. This blog will explain in simple terms how to use QueryString.
If your page is Default.aspx and you need to pass the NameValue combination, name=myname, then the QueryString would be Default.aspx?name=myname.
Now our problem is to pass variables for the categories
category1=object1
category2=object2
category2=object3
So we are having 1 value for category1 and 2 values for category2;
In your aspx page, add the following Namespaces,
using System.Collections.Specialized;
Now from the Key-Value pair in QueryString, to obtain all the keys, we use the following code,
String[] arr1 = coll.AllKeys;
Now to get the Values for Keys,
It is evident that in arr2 you will have only 1 value, and arr3 will have 2 values.
Advantages of using QueryString
- It is very easy.
Disadvantages of using QueryString
- QueryString have a max length, If you have to send a lot information this approach does not work.
QueryString
is visible in your address part of your browser so you should not use it with sensitive information.QueryString
can not be used to send & and space characters.