asp.net.ph

Skip Navigation Links

Controls You Can Use on Web Forms   ASP.NET Standard Controls   Label Control


The Label control can be used to act as an active caption associated with another Web server control, such as a TextBox control.

The Label control cannot receive the user input focus. However, by associating the Label control with another control, users can navigate to the associated control by simultaneously pressing the ALT key with an access key that you define for the Label control.

To use a Label Web server control as a caption

  1. Set the Label control’s AssociatedControlID property to the ID of the control for which you want the Label control to be the caption.
  2. Set the Label control’s AccessKey property to a single letter or number to define an access key.

    NOTE: If you associate the Label control with a button, when users simultaneously press the ALT key with the access key for the Label control, the button is clicked.

  3. Optionally set the Text property of the Label control to display an underlined character that indicates the access key.

The following example shows how to use a Label control as a caption for a TextBox control. When the page renders, users will be able to press ALT+L to navigate to the text box. The letter L in the Label is underlined.

<asp:Label id="Label1" runat="server"
   accesskey="L"
   associatedcontrolid="lastName"
   text="Enter <u>L</u>ast Name:" />

<asp:TextBox id="lastName" runat="server" />


© 2025 Reynald Nuñez and asp.net.ph. All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note