QueryString:
It is one of the client - side statemanagement techniques in asp.net. 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
" http://www.sitename.com/welcome.aspx?firstname=aspdotnet&lastname=sekhar".
- 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.
example:
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.
Conclusion:
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.
0 comments:
Post a Comment
Note: only a member of this blog may post a comment.