语言

WebControl.AccessKey 属性

定义

获取或设置访问密钥,使你能够快速导航到 Web 服务器控件。

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

属性值

用于快速导航到 Web 服务器控件的访问密钥。 默认值为 Empty,指示未设置此属性。

属性

例外

指定的访问键既不是,null也不是Empty单个字符串。

示例

下面的示例演示如何设置和使用 AccessKey 控件的属性 TextBox 。

Important

此示例有一个接受用户输入的文本框,这是潜在的安全威胁。 默认情况下,ASP.NET 网页验证用户输入是否不包含脚本或 HTML 元素。 有关详细信息,请参阅 脚本攻击概述。

<%@ 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 服务器控件的键盘快捷方式。 这使你可以通过按 Alt 键和键盘上指定字符的键快速导航到控件。 例如,将控件的访问键设置为字符串 "D" 表示用户可以通过按 Alt+D 导航到控件。

仅允许属性 AccessKey 使用单个字符串。 如果尝试将此属性设置为既不是 null, Empty也不是单个字符串的值,则会引发异常。

注释

此属性仅在 Internet Explorer 4.0 及更高版本中受支持。

适用于

另请参阅