When you add a Label control to your page you can associate the label to a control, for example to a TextBox or CheckBox etc. If you use the AssociatedControlID and associate a control to the label, the runtime will automatically render the “for” attribute to the label element (The “for” attribute is use to specify which control the label is associated to).
<asp:textbox id="TextBox1" runat="server"<
<asp:label id="Label1" associatedcontrolid="TextBox1" text="Label" runat="server"<>/asp:label<
<asp:textbox id="TextBox1" runat="server"<
The control above will be genereated to the following code at runtime:
<label id="Label1" for="TextBox1">Label</label>
<input id="TextBox1" name="TextBox1"></asp:textbox>
<asp:textbox runat="server">
If the “for” attribute is added to a label element, you can click the mouse button on the label and the associated control (in the above example the TextBox) will be selected. If you associate a checkbox to a label, the checbox will be selected or deslected if you click on the label assocated for the checkbox.
Tuesday, March 18, 2008
The Label control's AssociatedControlID property.
Subscribe to:
Post Comments (Atom)

No comments:
Post a Comment