ASP. NET Request and name (Form element value)

Source: Internet
Author: User

In ASP. NET, the following methods can be used to obtain the values of page elements in the background:
Request. Form (post), request. querystring (get), request. Params, and so on.

Of course, you can also directly use the index of the request itself.

-----

Sometimes, the values of form elements (such as the drop-down list) on our page are dynamically changed through Ajax (JS), and then used in the background. value can no longer be obtained.

What should we do at this time?

1. You can use a hidden control to store the selected values. Then obtain the value of the hidden control in the background.

2. We should know that the value passing of the form element is identified by the name attribute (whether post or get ).

No matter how the value changes, the name of the element remains unchanged. In ASP. NET, it indicates that the uniqueid is unchanged. Then we can use

Request [***. uniqueid] to obtain the element value.

------

How can we get the value if there are multiple elements with the same name on the page?

You can also obtain the request and several related (object) attributes. By default, the obtained values are separated by commas.

But what if the input value in the form element itself contains a comma?

", We seldom notice that several (object) attributes of the Request contain a pair of methods (get and getvalues ). They can actually get the passed element values.

When multiple elements with the same name exist:

Get values are separated by commas (,), regardless of whether the element value contains commas.

Getvalues stores the obtained element values in arrays instead of commas.

We can imagine that get is another layer of packaging for getvalues (array join method connection)

Therefore, if you want to obtain the values of multiple elements with the same name, you can use getvalues ..

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.