asp.net - How to use associated control id in Label

AssociatedControlID in Label Server Control
The Label is an ASP.NET web server control that displays text on the web page. Label control’s AssociatedControlID property gets or sets the identifier for a server control that the Label control is associated with.

The AssociatedControlID property value type is a String. This String represents the ID of server control in the web form. The default value of this property is an empty String which means the Label server control is not associated with any other server control.

By using this property we can extend the functionality of the associated control. We can use the Label control as a caption for other control or we can set the tab index or hotkey for associated server control.

We can set the Label AccessKey property to provide the hotkey for associated control. We also can use the Label Text property to set a caption for associated server control.

The following ASP.NET C# example code demonstrates to us how can we use the AssociatedControlID property of label server control in an ASP.NET application.
LabelAssociatedControlID.aspx

<%@ Page Language="C#" %>

<!DOCTYPE html>

<script runat="server">

</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>How to use associated control id (AssociatedControlID) in Label</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h2 style="color:Navy">Label Example: AssociatedControlID</h2>
        <asp:Label 
             ID="Label1" 
             runat="server"
             ForeColor="CadetBlue"
             Text="<u>U</u>ser Name"
             ToolTip="Color label"
             AccessKey="U"
             AssociatedControlID="TextBox1"
             >
        </asp:Label>
        <asp:TextBox 
             ID="TextBox1" 
             runat="server"
             BackColor="SeaGreen"
             ForeColor="AliceBlue"
             >
        </asp:TextBox>
    </div>
    </form>
</body>
</html>