C # What is the difference between request. Params and request. querystring?

Source: Internet
Author: User
Tags servervariables
Request. Params

14:02:22 | category: Asp.net
| Label: | large font size, small/medium subscription

Request. Params is actually a set of requests. querystring, request. Form, request. Cookies, and request. servervariables.

If you want to transmit data on two pages, you can only use request. querystring, request. Form, and request. Cookies.

Request. Params searches for data in querystring, form, server variable, and cookies,

He first searches for data in the querystring set. If the data is found in querystring, the data is returned. If the data is not found, he searches for data in the form set and returns the result, otherwise, search for data in the next collection.

Request. Params ["ID"]

Request. Form ["ID"]

Request. querystring ["ID"]

Usage and difference?

Request. Params is a set of all post and get values. Request. form is a set of post values.

Javascript uses 'name'

Incorrect javascript can cause errors in form passing values

========================================================== ===

A function of the request object under. NET is to obtain the data submitted by the client, which is also very familiar to everyone. Even so, there are several different ways of writing that may not be understandable to everyone.

Strmessage = request ("MSG ")

Strmessage = request. Form ("MSG ")

In addition, all the code written by many people is in the form of request (""). Of course, there is nothing wrong with this method.

No matter which set can be directly obtained through request (""), there is a problem here. If the get method and post method submit the same variable, for example, if username = sunny, do you use request ("username") to obtain the data obtained from get or post? However, you should note that the request object has several sets to obtain the data submitted by the client. Generally, querystring, form, and servervariables are commonly used.

Here is an example to illustrate this problem:

First, create an HTML page: index.html

<HTML>

<Head>

<Title> </title>

</Head>

<Body>

<P> enter your advantages </P>

<Form method = "Post" Action = "search. aspx? Holobby = 0000 ">

<P>

<Input type = "text" name = "holobby" size = "20"> <br>

<Input type = "checkbox" name = "holobby" value = "justice"> justice <input type = "checkbox" name = "holobby" value = "Honest"> honest

</P>

<P> <input type = "Submit" value = "OK" name = "B1"> <input type = "reset" value = "Refill" name = "B2">

</P>

</Form>

</Body>

Create a new page, search. aspx, and the page does not need anything. Here, the problem is explained. The background code is as follows:

Code

String str1 = requet. Form ["holobby"]

String str2 = requet. querystring ["holobby"]

String str3 = request. Params ["holobby"]

String str4 = request. servervariables ["holobby"]

String str5 = request ["holobby"]

I entered "handsome" on the index.html page, and selected both of the following checkboxes. click the button to submit the data to the search. ASPX page.

Str1 = "handsome, just, honest"

Str2 = "0000 ";

Str3 = "0000, long handsome, just, honest"

Str4 = "";

Tr5 = "0000 ";

Therefore, when the problem arises, we should have thought that there is a sequence in which requests fetch data from these sets. The order from the front to the back is querystring, form, and servervariables.

Request. form is actually used to obtain the data submitted by form.

Request. querystring is actually used to obtain the data submitted by the get method.

Request. params consists of several parts: the collection of querystring + form + servervariable + cookies. in the preceding example, str3 = request ["holobby"] obtains a set composed of these components.

Request. servervariables is used to obtain client-related information, such as the IE type and IP address.

The request object searches for the variables in these sets in order of this order. If there is any matching variable, it will be aborted and the subsequent variables will be ignored. In the preceding example, str5 = request ["holobby"] obtains the data submitted by the get method.

Therefore, in order to improve efficiency, reduce unnecessary search time, and standardize the program, we recommend that you use the request. Set method, such as request. Form ("Hoby ").

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.