Sunday, January 31, 2010

AssociatedControlID of Asp.Label control in Asp.net

Hi All,

Today i have found one interesting part of Asp.Net Label control. Label server control have one property AssociatedControlID.

Problem : without asssigning the AssociatedControlID property a Asp.net Label server control rendered as "span" which is not satisfied the client requirement of 'it should render as label for accessibility'

Here is the output before and after,

Before,

span id="form_103_lblFirst_Name">First Name /span

Assigned "AssociatedControlID" property and Result after,

  123 lblTitle.AssociatedControlID = txtName.ID;



label id="form_103_lblFirst_Name" for="form_103_First_Name">First Name /label

Solution : I have assigned the AssociatedControlID to the Asp.net Label server control to the textbox.ID to which it refering to. and found that it is rendered to "label" html tag which i required it also includes 'for' property which references the ID of Associated Control.

Happy Coding :)

No comments:

Post a Comment