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,表示未设置此属性。

属性

例外

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

示例

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

重要

此示例具有一个接受用户输入的文本框,这是一个潜在的安全威胁。 默认情况下,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 及更高版本中受支持。

适用于

另请参阅