Using Access Key or Hot Key in ASP.NET

This article explain you how to set a access key or hot key on ASP.NET controls to navigate a specific control on the page without using mouse.
  • 4849

An access key or a hot key allows you to press the ALT+ another specified key to navigate a specific control on the page without help of mouse. User can set an access key on a specified control like textbox, listbox or a label control.
This article explain how to set a access key on a Label control in
ASP.NET. When the page renders, user will be able to pres ALT+ the
specific key defined for each label.


How to set an access key by using a Label control

  1. Add a label or other control on which you want to set the access key.
  2. In the label control, set the AccessKey to letter or number to use with ALT key, then set the AssociatedControlID to the ID of the control to set the focus on when the ALT-key sequence is pressed and optionally highlight the
    text as underline it or use other indicator to the text property.

The following example shows the markup for a label control and a textbox control with the letter N,A,Q and J underlined to indicate that the access key for the text


When you press ALT+ any access key defined for each control on the page, you can directly navigate that control without using the mouse. Lets see the code snippets:  

Code Snippets

<%@ Page Language="vb" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "">
<html xmlns="" >
<head id="Head1" runat="server">
   <title>ASP.NET Label HotKeys</title>
   <form id="form1" runat="server">
   <div id="container">
   <h3>AccessKey for ASP.NET Label Control</h3>
   <asp:Label ID="labName" runat="server"
      AccessKey="N" AssociatedControlID="txtName" Text="Full <u>N</u>ame"></asp:Label>
   <asp:TextBox ID="txtName" runat="server"></asp:TextBox><br /><br />
   <asp:Label ID="LabelAdd" runat="server"
      AccessKey="A" AssociatedControlID="txtAddress" Text="<u>A</u>ddress"></asp:Label>
   <asp:TextBox ID="txtAddress" runat="server"></asp:TextBox><br /><br />
   <asp:Label ID="LabelQual" runat="server"
          AccessKey="Q" AssociatedControlID="txtQual" Text="<u>Q</u>ualification"></asp:Label>
   <asp:DropDownList ID="txtQual" runat="server">
   </asp:DropDownList><br /><br />
   <asp:Label ID="labMonth" runat="server"
          AccessKey="J" AssociatedControlID="drpMonth" Text="Month of <U>J</U>oining"></asp:Label>  
asp:DropDownList ID="drpMonth" runat="server">

I hope this article will help you to understand how to use access key or hot key in ASP.NET.


More Articles

© 2020 DotNetHeaven. All rights reserved.