Social Icons

Wednesday, 26 June 2013

Beginers tutorial for how to use QueryString in Asp.Net,Encoding,Decoding, Pass Multiple Values throgh QueryString

QueryString Usage in Asp.Net


In my previous article i explained Architecture of wpf, Asp.Net Ajax Tutorial,ViewState in Asp.Net Tutorial,Hidden Field in Asp.Net and various articles on WPF and Asp.Net and Ajax. Now we will see about QueryString Usage in Asp.Net i.e  what is the purpose of Querystring, when to use Querystring in, what is the need of encoding and decoding QueryString in Asp.Net, Ways to pass values to different pages or same page for different requests,How to pass multiple values through QueryString, How to Build QueryString in Asp.Net.



It is one of the client - side statemanagement techniques in It is one of technique to send variable values to another pages in Asp.Net through URL. Variable values are appended to URL while redirecting or Transfering to another webform or html page in Asp.Net.

       For Sending values to another page we will use QueryString Property of Request Object. While searching on the net you may see URL's like
  • In the above URL the information after ? symbol is called as QueryString.
  • QueryString has two parts i.e Key and Value.
  • We can send multiple values through QueryString Seperated By & Symbol.
  • QueryString Collection is a NameValueCollection internally where we can access keys using by name or by index.

How to add QueryString Information to URL:

     We know Response.Redirect("URL") is used to transfer current user to another page. We can use same to send user to another page along with QueryString Key- Values. All we have to do is to add QueryString information to URL and add this URL to Response.Redirect.
 To append QueryString information to URL or to add multiple values to URL we will follow below approaches.

We can directly place the querystring information from controls to Url like below

Another way is using string.Format method to send multiple values through

Reading QueryString Values from URL:

In the target page we can read QueryString Values from QueryString Collection using Request.QueryString[] Property. We can read QueryString Values through key name or by index.

  To Read encoded QueryString use Server.UrlDecode()

  Optimized way of reading QueryString:

It is better to check whether QueryString value is supplied or not before using QueryString Values using string.IsNullOrEmpty() method.

Need of Encoding and Decoding QueryString:

  • URL of QueryString should contain only ASCII characters only. So if you are passing other than ASCII Characters then they need to be encoded.
  • .Net Framework provides HttpServerUtility.UrlEncode and HttpServerUtility.UrlDecode methods for encoding and decoding Non - ASCII characters

Advantages of QueryString:

  • Light weight and not consume any server resource.
  • Easy to use and Efficient Technique.
  • Broad Support. Almost all browsers and devices supports this.
  • Seo Friendly. where user can bookmark pages easily.

Disadvantages of QueryString: 

  •  Limited Capacity: Most browsers and client - devices allow upto 255 characters limit on URL Length.
  • We can pass information in string format only, to pass objects and large volumes of data we have to do lot more things.
  • Security: Information send through QueryString will seen by Users and can be trapped.


I hope you got atmost details about QueryString usage in Asp.Net, How to pass multiple values throgh querystring, How to append information to QueryString, Reading QueryString Values, Encoding and Decoding QueryString, Advantages and Disadvantages of QueryString etc.


Related Tutorials

1 comment:

  1. Hi Sekhar please write article on hoe to include in blog posts syntax highlighter.


Please Give your Valuable Suggestions,Questions and Comments to improve my blog.