Introducing DotNetFunda.com on mobile http://m.dotnetfunda.com ! Be with DotNetFunda.com on the go !
Go to DotNetFunda.com
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 7440 |  Welcome, Guest!   Register  Login
Home > Articles > ASP.NET > How to work with QueryString?

How to work with QueryString?

2 vote(s)
Rating: 4.5 out of 5
Article posted by Ganeshji on 7/30/2010 | Views: 3753 | Category: ASP.NET | Level: Beginner red flag


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.

Page copy protected against web site content infringement by Copyscape
Found interesting? Add this to:



Please Sign In to vote for this post.

Experience:1 year(s)
Home page:
Member since:Saturday, July 24, 2010
Level:Starter
Status: [Member]
Biography:
 Responses
Posted by: Akiii | Posted on: 07 Jun 2011 01:23:53 AM | Points: 25

hi,

It helped me in understand the concept...
Keep posting...

Thanks and Regards
Akiii

Posted by: Ganeshji | Posted on: 08 Jun 2011 08:45:32 PM | Points: 25

Thnx Akii!

>> Write Response - Respond to this post and get points
Related Posts

This article describes how to specify an external AppSetting file from within web.config file and specify the settings value inside external file. It also describes related benefits and limitation of the external AppSetting file.

Many times we come across situations when we need to define our own settings( Rather than using AppSettings key/value). This article is just a try to make you understood how we can achieve such functionality.

Summary: An example of how we can extract data from HTML tables and create a DataSet object containing this data.

Read ConnectionString Information from Application Configuration File.

In this article we will take up a simple example and try to implement DI using Unity Application Blocks thus resulting in loosely coupled architecture.

More ...
About Us | Contact Us | The Team | Advertise | Software Development | Write for 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. | 5/21/2012 8:23:22 AM