获取或设置一个值,该值指示 TextBox 控件的 AutoComplete 行为
命名空间: System.Web.UI.WebControls
程序集: System.Web(在 System.Web.dll 中)
<ThemeableAttribute(False)> _ Public Overridable Property AutoCompleteType As AutoCompleteType
Dim instance As TextBox Dim value As AutoCompleteType value = instance.AutoCompleteType instance.AutoCompleteType = value
[ThemeableAttribute(false)] public virtual AutoCompleteType AutoCompleteType { get; set; }
[ThemeableAttribute(false)] public: virtual property AutoCompleteType AutoCompleteType { AutoCompleteType get (); void set (AutoCompleteType value); }
/** @property */ /** @attribute ThemeableAttribute(false) */ public AutoCompleteType get_AutoCompleteType() /** @property */ /** @attribute ThemeableAttribute(false) */ public void set_AutoCompleteType(AutoCompleteType value)
public function get AutoCompleteType () : AutoCompleteType public function set AutoCompleteType (value : AutoCompleteType)
<
属性值
类型: System.Web.UI.WebControls..::.AutoCompleteTypeSystem.Web.UI.WebControls..::.AutoCompleteType 枚举值之一,指示 TextBox 控件的 AutoComplete 行为。默认值为 None。
为协助完成数据输入,Microsoft Internet Explorer 5 和更高版本以及某些其他浏览器都支持一种称为“自动完成”的功能。“自动完成”监视一个文本框并创建用户输入的值的列表。用户在以后返回该文本框时,会显示该列表。用户只需从此列表选择值,而不用重新键入以前输入过的值。使用 AutoCompleteType 属性来控制 TextBox 控件的自动完成功能的行为。System.Web.UI.WebControls..::.AutoCompleteType 枚举用于表示可以应用到 AutoCompleteType 属性的值。
说明: |
---|
不是所有的浏览器都支持自动完成功能。请检查浏览器以确定兼容性。 |
默认情况下,TextBox 控件的 AutoCompleteType 属性设置为 AutoCompleteType.None。使用该设置,TextBox 控件与不同页面上具有相同 ID 属性的其他 TextBox 控件共享该列表。也可以根据类别,而不是根据 ID 属性,在 TextBox 控件之间共享列表。将 AutoCompleteType 属性设置为类别值(如 AutoCompleteType.FirstName、AutoCompleteType.LastName 等)之一时,所有相同类别的 TextBox 控件将共享同一个列表。通过将 AutoCompleteType 属性设置为 AutoCompleteType.Disabled,可以禁用 TextBox 控件的自动完成功能。
有关配置和启用自动完成功能的详细信息,请参考浏览器文档。例如,若要启用 Internet Explorer 5 版或更高版本中的自动完成功能,请从“工具”菜单中选择“Internet 选项”,然后选择“内容”选项卡。单击“自动完成”按钮,查看并修改自动完成功能的各种浏览器选项。
有关 Internet Explorer 中“自动完成”功能的更多信息,请在 MSDN Library 中搜索“Using AutoComplete in HTML Forms”(在 HTML 窗体中使用自动完成)。
无法通过主题或样式表主题设置此属性。有关更多信息,请参见 ThemeableAttribute和 ASP.NET 主题和外观概述。
下面的代码示例演示如何使用 AutoCompleteType 枚举来指定 TextBox 控件的 AutoComplete 类别。
安全说明: |
---|
此示例有一个接受用户输入的文本框,这是一个潜在的安全威胁。默认情况下,ASP.NET 网页验证用户输入是否不包括脚本或 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 > <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="C#" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html > <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>