Sdílet prostřednictvím


How to: Use Label Web Server Controls as Captions

You can use the Label Web server control to act as an active caption in front of 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+N to navigate to the text box. The letter N in the Label is underlined.

    <asp:Label 
        AccessKey="N"
        AssociatedControlID="TextBox1" 
        ID="Label1" 
        runat="server"
        Text="<u>N</u>ame:">
    </asp:Label>
    &nbsp;
    <asp:TextBox ID="TextBox1" runat="server" />
    

See Also

Reference

Label Web Server Control Overview