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

定義

取得或設定便捷鍵 (Access Key),可讓您快速巡覽至 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 Web 網頁會驗證使用者輸入未包含指令碼或 HTML 項目。By default, ASP.NET Web pages validate that user input does not include script or HTML elements. 如需詳細資訊,請參閱 Script Exploits Overview (指令碼攻擊概觀)。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. 如果您嘗試將此屬性設定為不是nullEmpty,也不是單一字元字串的值,則會擲回例外狀況。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.

適用於

另請參閱