ASP.NET Web Forms > Label and Literal

Associate a Label to TextBox in ASP.NET Web Forms

How to associate an asp:Label with a Text Box or other Form control?


In case we need to associate a text label with any control so that clicking on the text focus on the control (eg. TextBox), we can use this approach. 

ASPX Page
<p> 
<asp:Label ID="lblName" runat="server" AssociatedControlID="txtFirstName" Text="First Name: " />
<asp:TextBox ID="txtFirstName" runat="server" />
</p>

AssociateControlID property of the Label control can be specified to the TextBox id that associates the Label to the TextBox. Clicking on the Label control focuses the TextBox. 

 Views: 3681 | Post Order: 12



Write for us






Hosting Recommendations