An access key (also known as a hot key) allows users to press the ALT key plus another key to jump to a specific control on the page without using the mouse.
You can set an access key on a specific control, such as a or control. Alternatively, you can set an access key for a control, and then specify that the Label control is associated with another control. This approach enables you to use the Label control as a caption, allowing you to indicate the access key with an underlined letter in the label text.
Access keys and other keyboard shortcuts are not supported on all browsers.
To set an access key for a specific ASP.NET Web server control
Set the control's AccessKey property to the letter or number that you want to use with ALT key as a keyboard shortcut.
For example, to set a control's access key to ALT+S, set the control's AccessKey property to S.
Some ALT-key sequences might be reserved in the browser. For example, in Internet Explorer, ALT+F opens the File menu. The browser determines whether to give precedence to your ALT-key sequence or to the brower's reserved keys.
To set an access key by using a Label control
Add a Label control to the page to act as a caption for the control that you want to put focus on with an access key.
In a Label control, set the following properties:
В В В Set this property to the letter or number to use with the ALT key, such as S to support ALT+S.
В В В Set this property to the ID of the control to set the focus on when the ALT-key sequence is pressed.
В В В Optionally, use HTML to add an underline or other indicator to the Text property.
The following code example shows the markup for a Label control and a TextBox control. The Label control displays a caption for the TextBox control, with the letter
Lunderlined to indicate that the access key for the text box is ALT+L.
В Copy Code
<asp:Label ID="Label1" runat="server" AccessKey="L" AssociatedControlID="TextBox1" Text="<u>L</u>ast name: "> </asp:Label> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
Setting focus by using an access key from a Label control requires that client scripting is enabled in the browser.