Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

WebControl.AccessKey Property

Gets or sets the access key (underlined letter) that allows you to quickly navigate to the Web server control.

[Visual Basic]
Public Overridable Property AccessKey As String
[C#]
public virtual string AccessKey {get; set;}
[C++]
public: __property virtual String* get_AccessKey();
public: __property virtual void set_AccessKey(String*);
[JScript]
public function get AccessKey() : String;
public function set AccessKey(String);

Property Value

The access key for quick navigation to the Web server control. The default value is String.Empty, which indicates that this property is not set.

Exceptions

Exception Type Condition
ArgumentException The specified access key is not either a null reference (Nothing in Visual Basic), String.Empty, or a single character string.

Remarks

Use the AccessKey property to specify the keyboard shortcut for the Web server control. This allows you to navigate quickly to the control by pressing the ALT key and the key for the specified character on the keyboard. For example, setting the access key of a control to the string "D" indicates that the user can navigate to the control by pressing ALT+D.

Only a single character string is allowed for the AccessKey property. If you attempt to set this property to a value that is not a null reference (Nothing in Visual Basic), String.Empty, or a single character string, an exception is thrown.

Note   This property is supported only in Internet Explorer 4.0 and later.

Example

[Visual Basic, C#, JScript] The following example illustrates how to set and use the AccessKey property of a TextBox control.

[Visual Basic] 
<%@ Page Language="VB" AutoEventWireup="True" %>

<html>
 <head>
 
 </head>
 <body>
 
   <h3>AccessKey Property of a Web Control</h3>
 
 <form runat="server">
 
   <asp:TextBox id="TextBox1" 
     AccessKey="Y" 
     Text="Press Alt-Y to get focus here" 
     Columns="45"
     runat="server"/>
 
   <p>
 
   <asp:TextBox id="TextBox2" 
     AccessKey="Z" 
     Text="Press Alt-Z to get focus here" 
     Columns="45"
     runat="server"/>
 
 </form>
 
 </body>
 </html>
    

[C#] 
<%@ Page Language="C#" AutoEventWireup="True" %>
<html>
 <head>
 
 </head>
 <body>
 
   <h3>AccessKey Property of a Web Control</h3>
 
 <form runat="server">
 
   <asp:TextBox id="TextBox1" 
     AccessKey="Y" 
     Text="Press Alt-Y to get focus here" 
     Columns="45"
     runat="server"/>
 
   <p>
 
   <asp:TextBox id="TextBox2" 
     AccessKey="Z" 
     Text="Press Alt-Z to get focus here" 
     Columns="45"
     runat="server"/>
 
 </form>
 
 </body>
 </html>
    

[JScript] 
<%@ Page Language="JScript" AutoEventWireup="True" %>

<html>
 <head>
 
 </head>
 <body>
 
   <h3>AccessKey Property of a Web Control</h3>
 
 <form runat="server">
 
   <asp:TextBox id="TextBox1" 
     AccessKey="Y" 
     Text="Press Alt-Y to get focus here" 
     Columns="45"
     runat="server"/>
 
   <p>
 
   <asp:TextBox id="TextBox2" 
     AccessKey="Z" 
     Text="Press Alt-Z to get focus here" 
     Columns="45"
     runat="server"/>
 
 </form>
 
 </body>
 </html>
    

[C++] No example is available for C++. To view a Visual Basic, C#, or JScript example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family

See Also

WebControl Class | WebControl Members | System.Web.UI.WebControls Namespace

Show:
© 2015 Microsoft