WebControl.AccessKey 屬性

定義

取得或設定便捷鍵 (Access Key),可讓您快速巡覽至 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 Web 網頁會驗證使用者輸入未包含指令碼或 HTML 項目。 如需詳細資訊,請參閱 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 服務器控制項的鍵盤快速鍵。 這可讓您按下鍵盤上指定字元的 ALT 鍵和按鍵,快速流覽至控制項。 例如,將控制項的存取鍵設定為字串 "D" ,表示使用者可以按 ALT+D 流覽至控制項。

屬性只允許 AccessKey 單一字元字串。 如果您嘗試將此屬性設定為不是 nullEmpty 或單一字元字串的值,則會擲回例外狀況。

注意

此屬性僅在 Internet Explorer 4.0 和更新版本中受到支援。

適用於

另請參閱