NET Framework version 2.0新增加了一个property——AutoCompleteType。
To assist with data entry, Microsoft Internet Explorer 5 and later and Netscape support a feature called 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. Use the AutoCompleteType property to control the behavior of the AutoComplete feature for a TextBox control. The System.Web.UI.WebControls.AutoCompleteType enumeration is used to represent the values that you can apply to the AutoCompleteType property.
上面是MSDN的原文。
在自定义控件中如何实现AutoCompleteType呢?如果控件继承自webcontrol,那么它将自带这个property。
当页面运行起来,控件在showhistorylist的时候,首先去判断AutoCompleteType是否为None,如果是None,那么就根据control的ID来show history list;如果该属性不为None,则根据该type来show history list。
这就要求我们在保存历史信息的时候必须分开处理这两种情况。下面是保存cookie的一段示范代码:
if (this.AutoCompleteType != "None")
{
this.SetCookie(this.AutoCompleteType, this.Text);
}
else
{
this.SetCookie(this.ID, this.Text);
}