Cainiao record: textbox read-only setting method in ASP. net2.0

Source: Internet
Author: User

Test an ASP. for a net2.0 page, a textbox needs to control the user input format and change the content in script mode. To prevent the user from directly inputting the content, the readonly attribute of the textbox is set to true.

As a result, no matter how the client script changes the textbox value, the text attribute on the server remains the same as the initial value, because the debugging was coming off work yesterday, it was a bit confusing. This morning, I suddenly thought it might be related to this readonly attribute. Because it is a server attribute, the result is normal after this attribute is removed. Since the Server property and client property have different roles, you cannot directly set them in the control property, so you can only useAttributes ["readonly"] = "true"This must be set only for the readonly client. After testing, the read-only effect of preventing direct input by the client is achieved.

After comparison, we found that the client code generated by the two methods uses the readonly client attribute of the HTML Tag. The difference is that the value generated by the server attribute is different from that generated by the client attribute, when the Server property is set to true, the client changes to"Readonly = "readonly"", And the client property changes to"Readonly = "true"".

Therefore, if you want to set the textbox client to read-only, you must use"Attributes ["readonly"] = "true"You cannot directly modify the server control attributes.

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.