TextBox.AutoCompleteType TextBox.AutoCompleteType TextBox.AutoCompleteType TextBox.AutoCompleteType Property

定義

取得或設定值,表示 TextBox 控制項的 AutoComplete 行為。Gets or sets a value that indicates the AutoComplete behavior of the TextBox control

public:
 virtual property System::Web::UI::WebControls::AutoCompleteType AutoCompleteType { System::Web::UI::WebControls::AutoCompleteType get(); void set(System::Web::UI::WebControls::AutoCompleteType value); };
[System.Web.UI.Themeable(false)]
public virtual System.Web.UI.WebControls.AutoCompleteType AutoCompleteType { get; set; }
member this.AutoCompleteType : System.Web.UI.WebControls.AutoCompleteType with get, set
Public Overridable Property AutoCompleteType As AutoCompleteType

屬性值

其中一個 AutoCompleteType 列舉型別 (Enumeration) 值,表示 TextBox 控制項的 AutoComplete 行為。One of the AutoCompleteType enumeration values, indicating the AutoComplete behavior for the TextBox control. 預設值為 NoneThe default value is None.

例外狀況

選取的值不是其中一個 AutoCompleteType 列舉值。The selected value is not one of the AutoCompleteType enumeration values.

範例

下列程式碼範例示範如何使用AutoCompleteType列舉來指定TextBox控制項的自動完成分類。The following code example demonstrates how to use the AutoCompleteType enumeration to specify the AutoComplete category for 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#" %>
<!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 runat="server">
    <title>AutoCompleteType example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <!-- You need to enable the AutoComplete feature on -->
      <!-- a browser that supports it (such as Internet   -->
      <!-- Explorer 5.0 and later) for this sample to     -->
      <!-- work. The AutoComplete lists are created after -->
      <!-- the Submit button is clicked.                  -->
    
      <h3>AutoCompleteType example</h3>
    
      Enter values in the text boxes and click the Submit <br/>
      button. <br/><br/> 
    
      <!-- The following TextBox controls have different  -->
      <!-- categories assigned to their AutoCompleteType  -->
      <!-- properties.                                    -->
      First Name:<br/>
      <asp:textbox id="FirstNameTextBox"
        autocompletetype="FirstName" 
        runat="server"/>
      <br/>
        
      Last Name:<br/>   
      <asp:textbox id="LastNameTextBox"
        autocompletetype="LastName" 
        runat="server"/>
      <br/>
      
      Email:<br/>   
      <asp:textbox id="EmailTextBox"
        autocompletetype="Email" 
        runat="server"/>
      <br/>
      
      <!-- The following TextBox controls have the same   -->
      <!-- categories assigned to their AutoCompleteType  -->
      <!-- properties. They share the same AutoComplete   -->
      <!-- list.                                          -->
      Phone Line #1:<br/>
      <asp:textbox id="Phone1TextBox"
        autocompletetype="HomePhone" 
        runat="server"/>
      <br/>
      
      Phone Line #2:<br/>
      <asp:textbox id="Phone2TextBox"
        autocompletetype="HomePhone" 
        runat="server"/>
      <br/>

    
      <!-- The following TextBox control has its          -->
      <!-- AutoCompleteType property set to               -->
      <!-- AutoCompleteType.None. All TextBox controls    -->
      <!-- with the same ID across different pages share  -->
      <!-- the same AutoComplete list.                    -->
      Category:<br/>   
      <asp:textbox id="CategoryTextBox"
        autocompletetype="None" 
        runat="server"/>
      <br/>
        
      <!-- The following TextBox control has the          -->
      <!-- AutoComplete feature disabled.                 -->
      Comments:<br/>   
      <asp:textbox id="CommentsTextBox"
        autocompletetype="Disabled" 
        runat="server"/>
      <br/>
      <br/><br/>  
      
      <asp:button id="SubmitButton"
        text="Submit"
        runat="Server"/>
    
    </form>
  </body>
</html>


<%@ Page Language="VB" %>
<!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 runat="server">
    <title>AutoCompleteType example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <!-- You need to enable the AutoComplete feature on -->
      <!-- a browser that supports it (such as Internet   -->
      <!-- Explorer 5.0 and later) for this sample to     -->
      <!-- work. The AutoComplete lists are created after -->
      <!-- the Submit button is clicked.                  -->
    
      <h3>AutoCompleteType example</h3>
    
      Enter values in the text boxes and click the Submit <br/>
      button. <br/><br/> 
    
      <!-- The following TextBox controls have different  -->
      <!-- categories assigned to their AutoCompleteType  -->
      <!-- properties.                                    -->
      First Name:<br/>
      <asp:textbox id="FirstNameTextBox"
        autocompletetype="FirstName" 
        runat="server"/>
      <br/>
        
      Last Name:<br/>   
      <asp:textbox id="LastNameTextBox"
        autocompletetype="LastName" 
        runat="server"/>
      <br/>
      
      Email:<br/>   
      <asp:textbox id="EmailTextBox"
        autocompletetype="Email" 
        runat="server"/>
      <br/>
      
      <!-- The following TextBox controls have the same   -->
      <!-- categories assigned to their AutoCompleteType  -->
      <!-- properties. They share the same AutoComplete   -->
      <!-- list.                                          -->
      Phone Line #1:<br/>
      <asp:textbox id="Phone1TextBox"
        autocompletetype="HomePhone" 
        runat="server"/>
      <br/>
      
      Phone Line #2:<br/>
      <asp:textbox id="Phone2TextBox"
        autocompletetype="HomePhone" 
        runat="server"/>
      <br/>

    
      <!-- The following TextBox control has its          -->
      <!-- AutoCompleteType property set to               -->
      <!-- AutoCompleteType.None. All TextBox controls    -->
      <!-- with the same ID across different pages share  -->
      <!-- the same AutoComplete list.                    -->
      Category:<br/>   
      <asp:textbox id="CategoryTextBox"
        autocompletetype="None" 
        runat="server"/>
      <br/>
        
      <!-- The following TextBox control has the          -->
      <!-- AutoComplete feature disabled.                 -->
      Comments:<br/>   
      <asp:textbox id="CommentsTextBox"
        autocompletetype="Disabled" 
        runat="server"/>
      <br/>
      <br/><br/>  
      
      <asp:button id="SubmitButton"
        text="Submit"
        runat="Server"/>
    
    </form>
  </body>
</html>

備註

為了協助資料輸入,Microsoft Internet Explorer 5 和更新版本,以及一些其他瀏覽器都支援稱為「自動完成」的功能。To assist with data entry, Microsoft Internet Explorer 5 and later and some other browsers support a feature referred to as AutoComplete. 自動完成會監視一個文字方塊,並建立使用者輸入的值清單。AutoComplete monitors a text box and creates a list of values entered by the user. 當使用者稍後返回文字方塊時,會顯示清單。When the user returns to the text box at a later time, the list is displayed. 使用者可以直接從這個清單中選取值,而不是重新輸入先前輸入的值。Instead of retyping a previously entered value, the user can simply select the value from this list. 使用屬性,即可控制TextBox控制項自動完成功能的行為。 AutoCompleteTypeUse the AutoCompleteType property to control the behavior of the AutoComplete feature for a TextBox control. 列舉是用來表示您可以套用AutoCompleteType至屬性的值。 System.Web.UI.WebControls.AutoCompleteTypeThe System.Web.UI.WebControls.AutoCompleteType enumeration is used to represent the values that you can apply to the AutoCompleteType property.

注意

並非所有瀏覽器都支援自動完成功能。Not all browsers support the AutoComplete feature. 請洽詢您的瀏覽器以判斷相容性。Check with your browser to determine compatibility.

根據預設, TextBox控制項AutoCompleteType的屬性會設定為。 AutoCompleteType.NoneBy default, the AutoCompleteType property for a TextBox control is set to AutoCompleteType.None. 使用此設定時, TextBox控制項會與具有相同ID屬性的TextBox其他控制項共用此清單,但在不同的頁面上。With this setting, the TextBox control shares the list with other TextBox controls with the same ID property across different pages. 您也可以根據類別(而TextBoxID是屬性),在控制項之間共用清單。You can also share a list between TextBox controls based on a category, instead of an ID property. 當您將AutoCompleteType屬性設定為其中一個類別目錄值( AutoCompleteType.FirstName例如、 AutoCompleteType.LastName等等)時,具有相同類別目錄TextBox的所有控制項都會共用相同的清單。When you set the AutoCompleteType property to one of the category values (such as AutoCompleteType.FirstName, AutoCompleteType.LastName, and so on), all TextBox controls with the same category share the same list. 您可以藉由TextBox AutoCompleteType將屬性設定為AutoCompleteType.Disabled,來停用控制項的自動完成功能。You can disable the AutoComplete feature for a TextBox control by setting the AutoCompleteType property to AutoCompleteType.Disabled.

如需設定和啟用自動完成功能的詳細資訊,請參閱瀏覽器檔。Refer to your browser documentation for details on configuring and enabling the AutoComplete feature. 例如,若要在 Internet Explorer 第5版或更新版本中啟用自動完成功能,請從 [工具] 功能表中選取 [網際網路選項],然後選取 [內容] 索引標籤。按一下 [自動完成] 按鈕,以查看及修改自動完成功能的各種瀏覽器選項。For example, to enable the AutoComplete feature in Internet Explorer version 5 or later, select Internet Options from the Tools menu, and then select the Content tab. Click the AutoComplete button to view and modify the various browser options for the AutoComplete feature.

如需 Internet Explorer 中 [自動完成] 功能的詳細資訊,請參閱MSDN Library中的使用 HTML 表單中的自動完成功能。For more information about the AutoComplete feature in Internet Explorer, see Using AutoComplete in HTML Forms in the MSDN Library.

這個屬性無法由佈景主題或樣式表主題設定。This property cannot be set by themes or style sheet themes. 如需詳細資訊, ThemeableAttribute請參閱和ASP.NET 主題和外觀For more information, see ThemeableAttribute and ASP.NET Themes and Skins.

適用於

另請參閱