ASP. NET background CS access foreground htmlselect Control Value

Source: Internet
Author: User

When developing a web page, we sometimes use the htmlselect control as the selection control for the list item, and sometimes modify its value (such as Ajax) using JS on the client ), however, the modified value cannot be accessed in the CS code of the server, because the modified form value of JS is not synchronously updated to ASP. net viewstate to hide the domain. The solution is as follows:

1. If you only access the selected value of the htmlselect control, you can use request. Form ["select1"]. tostring () to obtain

2. if you want to access the value and text values at the same time, you can add a hidden field in the form <asp: hiddenfield>, and synchronously update the value of this hidden field when the foreground JS updates the htmlselect control, then, the backend CS can obtain the value of the hidden domain.

Think about the MS bug. The value updated by JS in <asp: hiddenfield> can be accessed in the background, <select runat = "server"> the updated value of the control cannot be accessed by CS in the background.

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.