What you want to see on DotNetFunda.com ?
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 25428 |  Welcome, Guest!   Register  Login
 Home > Blogs > ASP.NET > The Query String ...
Umeshdwivedi

The Query String

 Blog author: Umeshdwivedi | Posted on: 11/7/2011 | Category: ASP.NET Blogs | Views: 1743 | Status: [Member] | Points: 75 | Alert Moderator   


Hi friends,

Today i am explain about query string this is power ful technique to pass the value.........
One common approach is to pass information using a query string in the URL. You will commonly find
this approach in search engines. For example, if you perform a search on the Google website, you'll be
redirected to a new URL that incorporates your search parameters. Here's an example:

http://www.google.ca/search?q=organic+gardening
The query string is the portion of the URL after the question mark. In this case, it defines a single
variable named q, which contains the "organic+gardening" string.
The advantage of the query string is that it's lightweight and doesn't exert any kind of burden on the
server. Unlike cross-page posting, the query string can easily transport the same information from page
to page. It has some limitations, however:
Information is limited to simple strings, which must contain URL-legal characters.
Information is clearly visible to the user and to anyone else who cares to
eavesdrop on the Internet.

•The enterprising user might decide to modify the query string and supply new
values, which your program won't expect and can't protect against.
Many browsers impose a limit on the length of a URL (usually from 1 to 2 KB). For
that reason, you can't place a large amount of information in the query string and
still be assured of compatibility with most browsers.

Adding information to the query string is still a useful technique. It's particularly well suited in
database applications where you present the user with a list of items corresponding to records in a
database, like products. The user can then select an item and be forwarded to another page with detailed
information about the selected item. One easy way to implement this design is to have the first page
send the item ID to the second page. The second page then looks that item up in the database and
displays the detailed information. You'll notice this technique in e-commerce sites such as
Amazon.com.
Using the Query String
To store information in the query string, you need to place it there yourself. Unfortunately, there is no
collection-based way to do this. Typically, this means using a special HyperLink control, or you can use a

 

Response.Redirect() statement like the one shown here:

// Go to newpage.aspx. Submit a single query string argument

// named recordID and set to 10.

int recordID = 10;
Response.Redirect("newpage.aspx?recordID=" + recordID.ToString());
You can send multiple parameters as long as you separate them with an ampersand (&), as
shown here:

// Go to newpage.aspx. Submit two query string arguments:

// recordID (10) and mode (full).

Response.Redirect("newpage.aspx?recordID=10&mode=full");

The receiving page has an easier time working with the query string. It can receive the values from
the QueryString dictionary collection exposed by the built-in Request object, as shown here:
 
string ID = Request.QueryString["recordID"];

If the query string doesn't contain the recordID parameter, or if the query string contains the
recordID parameter but doesn't supply a value, the ID string will be set to null.
Note that information is always retrieved as a string, which can then be converted to another simple
data type. Values in the QueryString collection are indexed by the variable name.

Happy programming

Umesh dwivedi




Latest Technology Trainer
And Part time software consultant
Found interesting? Add this to:


Experience:6 year(s)
Home page:http://www.dotnetfunda.com
Member since:Monday, January 03, 2011
Level:Starter
Status: [Member]
Biography:umesh dwivedi

 Responses

Biswarup90
Posted by: Biswarup90 | Posted on: 11/23/2011 | Level: Starter | Status: [Member] | Points: 15 | Alert Moderator 

I am trying to give some example about Query String.Query String is most importance topic in .net technology....

Query string is used to Pass the values or information form one page to another page.
Simple Syntax:
Request.QueryString(variable)[(index)|.Count]

Parameter variable :-

Specifies the name of the variable in the http query string to retrieve.
index :-
An optional parameter that enables you to retrieve one of multiple values for variable. It can be any integer value in the range 1 to Request.QueryString(variable).Count.

Retrieving Query Strings in ASP.NET
Retrieving query strings in ASP.NET is quite simple, what we need is just the following line of code:
Page.Request.QueryString[queryStringField];
or
Page.Request.QueryString[indexOfQueryString];

So If we need to retrieve the value of name field from this URL: http://google.com/tag?name=biswarup&role=user
Just do this inside of your ASP.NET code: Page.Request.QueryString["name"] or Page.Request.QueryString[0]. Lets look at how it work in simple source of code (google.aspx):

<%@ Page Language="C#" %>
<html>
<head>
<title>Query Strings in ASP.NET: Page 1</title>
<script language="C#" runat="server">
void GetQrStrng(object sender, EventArgs e)
{
// change the Response.Redirect parameter with your own location.
Page.Response.Redirect("query string path");
}
</script>
</head>
<body>
<form runat="server">
<asp:Button id="btn" onclick="GetQrStrng" text="Show String" runat="server" />
</form>
</body>
</html>

Biswarup Ghosh

Nil1401
Posted by: Nil1401 | Posted on: 12/30/2011 | Level: Starter | Status: [Member] | Points: 15 | Alert Moderator 

Yes Query String is still a strong feature of .net and i use it many times where security concern is not a matter.
Thanks Umesh for writing this article.


Thanks and Regards
Nilesh Rathod
Indore, India

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

More Blogs

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 find 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/22/2013 3:54:27 AM