ASP: inputattributes and labelattributes attributes of checkbox

Source: Internet
Author: User

Two new attributes are added to the checkbox control:InputattributesAndLabelattributes. By using these two attributes, you can easily add custom attributes to the label and input tags. However, attributes cannot be used to complete these two tasks. For example, the page defines an ASP: checkbox:

<asp:CheckBox ID="cbTest" Text="CheckBox" runat="server" />

Use in background codeAttributesAttribute to add an onclick event:

cbTest.Attributes.Add("onclick", "checkBoxClick(this)");

Then, browse the page and view the Page code:

<input id="cbTest" type="checkbox" name="cbTest" onclick="checkBoxClick(this);" /><label for="cbTest">CheckBox</label>

The background program adds an onclick event to the checkbox, but the label event cannot be added.LabelattributesAttribute to add an event to the label.

cbTest.InputAttributes.Add("onclick", "checkBoxClick(this)");
cbTest.LabelAttributes.Add("onclick", "checkBoxClick(this)");

View the Page code again:

<input id="cbTest" type="checkbox" name="cbTest" onclick="checkBoxClick(this)" /><label for="cbTest" onclick="checkBoxClick(this)">CheckBox</label>

It is found that the label has an onclick event. In the code above, we have used the inputattributes attribute to add events to the checkbox. This attribute achieves the same effect as the result of adding events using the attributes attribute. But they will be somewhat different. In some complex programs, Asp.net adds an additional <span> label to the checkbox when parsing the ASPX page, at this time, The onclick event added to the attributes attribute will be added to the span, and the second is not in the input. Therefore, we need the inputattributes attribute to add an event for the input.

 

 

 

 

 

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.