Jan 21 2006

AssociatedControlID in ASP.NET 2.0

Category:Bil@l @ 21:02

I am customizing the CreateUserWizard to add some fields when adding a new user, and noticed that property called: AssociatedControlID.

For example:

<asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="txtUserName">UserName</Label>
<asp:TextBox ID="txtUserName" runat="server" />

You can see that you have associated the Label FOR the TextBox. When the page runs, go to view source and you will find this:

<label for="txtUserName" id="UserNameLabel">UserName</label>
<input name="txtUserName" type="text" id="txtUserName" />

You will notice the FOR property added. This tells the Label that it is associated with the TextBox called *txtUserName.*
When you click your mouse on the label, the cursor will be active inside the TextBox, that is really cool :D




Comments are closed