TextBox.AutoCompleteType 属性

定义

获取或设置一个值,该值指示 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; }
[<System.Web.UI.Themeable(false)>]
member this.AutoCompleteType : System.Web.UI.WebControls.AutoCompleteType with get, set
Public Overridable Property AutoCompleteType As AutoCompleteType

属性值

AutoCompleteType

AutoCompleteType 枚举值之一,指示 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 枚举指定控件的自动完成类别 TextBoxThe 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 网页验证用户输入是否不包含脚本或 HTML 元素。By default, ASP.NET Web pages validate that user input does not include script or HTML elements. 有关详细信息,请参阅脚本侵入概述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. 使用 AutoCompleteType 属性控制控件的自动完成功能的行为 TextBoxUse the AutoCompleteType property to control the behavior of the AutoComplete feature for a TextBox control. System.Web.UI.WebControls.AutoCompleteType枚举用于表示可应用于属性的值 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.

默认情况下, AutoCompleteType 控件的属性 TextBox 设置为 AutoCompleteType.NoneBy default, the AutoCompleteType property for a TextBox control is set to AutoCompleteType.None. 通过此设置, TextBox 控件与 TextBox ID 不同页上具有相同属性的其他控件共享列表。With this setting, the TextBox control shares the list with other TextBox controls with the same ID property across different pages. 您还可以 TextBox 基于类别而不是属性在控件之间共享列表 IDYou 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.DisabledYou 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或更高版本中启用自动完成功能,请从 "工具" 菜单中选择 " Internet 选项",然后选择 "内容" 选项卡。单击 "自动完成" 按钮,查看并修改自动完成功能的各种浏览器选项。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 中的自动完成功能的详细信息,请参阅 使用 HTML 窗体中的自动完成功能。For more information about the AutoComplete feature in Internet Explorer, see Using AutoComplete in HTML Forms.

无法通过主题或样式表主题设置此属性。This property cannot be set by themes or style sheet themes. 有关详细信息,请参阅 ThemeableAttributeASP.NET 主题和外观For more information, see ThemeableAttribute and ASP.NET Themes and Skins.

适用于

另请参阅