WebControl.AccessKey WebControl.AccessKey WebControl.AccessKey WebControl.AccessKey Property

定义

获取或设置使您得以快速导航到 Web 服务器控件的访问键。Gets or sets the access key that allows you to quickly navigate to the Web server control.

public:
 virtual property System::String ^ AccessKey { System::String ^ get(); void set(System::String ^ value); };
[System.ComponentModel.Bindable(true)]
public virtual string AccessKey { get; set; }
member this.AccessKey : string with get, set
Public Overridable Property AccessKey As String

属性值

用于快速定位到 Web 服务器控件的访问键。The access key for quick navigation to the Web server control. 默认值为 Empty,表示未设置此属性。The default value is Empty, which indicates that this property is not set.

异常

指定的访问键不是 nullEmpty,也不是单个字符串。The specified access key is neither null, Empty nor a single character string.

示例

下面的示例演示如何设置和使用AccessKey TextBox控件的属性。The following example illustrates how to set and use the AccessKey property of a TextBox control.

重要

此示例具有一个接受用户输入的文本框,这是一个潜在的安全威胁。This example has a text box that accepts user input, which is a potential security threat. 默认情况下,ASP.NET 网页验证用户输入是否不包含脚本或 HTML 元素。By default, ASP.NET Web pages validate that user input does not include script or HTML elements. 有关详细信息,请参阅脚本侵入概述For more information, see Script Exploits Overview.

<%@ Page Language="C#" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
 <head>
    <title>AccessKey Property of a Web Control</title>
</head>
 <body>
 
   <h3>AccessKey Property of a Web Control</h3>
 
 <form id="form1" runat="server">
 
   <asp:TextBox id="TextBox1" 
     AccessKey="Y" 
     Text="Press Alt-Y to get focus here" 
     Columns="45"
     runat="server"/>
 
   <br />
 
   <asp:TextBox id="TextBox2" 
     AccessKey="Z" 
     Text="Press Alt-Z to get focus here" 
     Columns="45"
     runat="server"/>
 
 </form>
 
 </body>
 </html>
    
<%@ Page Language="VB" AutoEventWireup="True" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
 <head>
    <title>AccessKey Property of a Web Control</title>
</head>
 <body>
 
   <h3>AccessKey Property of a Web Control</h3>
 
 <form id="form1" runat="server">
 
   <asp:TextBox id="TextBox1" 
     AccessKey="Y" 
     Text="Press Alt-Y to get focus here" 
     Columns="45"
     runat="server"/>
 
   <br />
 
   <asp:TextBox id="TextBox2" 
     AccessKey="Z" 
     Text="Press Alt-Z to get focus here" 
     Columns="45"
     runat="server"/>
 
 </form>
 
 </body>
 </html>
    

注解

AccessKey使用属性指定 Web 服务器控件的键盘快捷方式。Use the AccessKey property to specify the keyboard shortcut for the Web server control. 这使你可以通过按 ALT 键和键盘上指定字符的键来快速导航到控件。This allows you to navigate quickly to the control by pressing the ALT key and the key for the specified character on the keyboard. 例如,将控件的访问键设置为字符串"D"表示用户可以通过按 ALT + D 导航到控件。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.

对于AccessKey属性,只允许一个字符串。Only a single character string is allowed for the AccessKey property. 如果尝试将此属性设置为既null不是、 Empty,也不是单字符字符串的值,则会引发异常。If you attempt to set this property to a value that is neither null, Empty, nor a single character string, an exception is thrown.

备注

只有 Internet Explorer 4.0 和更高版本支持此属性。This property is supported only in Internet Explorer 4.0 and later.

适用于

另请参阅