Blog author: Umeshdwivedi
| Posted on: 11/7/2011 | Category: ASP.NET Blogs
| Views: 1743 | Status: [Member]
| Points: 75
| Alert Moderator
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:
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
Information is clearly visible to the user and to anyone else who
eavesdrop on the Internet.
The enterprising user might decide to modify the query string and
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
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;
You can send multiple parameters as long as you separate them with
an ampersand (&), as
// Go to newpage.aspx. Submit two query string arguments:
// recordID (10) and 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
Values in the QueryString collection are indexed by the variable name.
Latest Technology Trainer
And Part time software consultant
Found interesting? Add this to: