作者:herobeast
时间:2007-7-18
/Files/HeroBeast/autocompletetextboxcontrol.rar

我想大家在用163邮箱给朋友写信的时候,已经感受过“自动完成”功能了吧!



下面是我刚做一个类似于那样的控件.如下图:
具有自动完成功能的TextBox控件
1.js

 

    }

2.源代码:
 1 using System;
 2 using System.Collections.Generic;
 3 using System.ComponentModel;
 4 using System.Text;
 5 using System.Web;
 6 using System.Web.UI;
 7 using System.Web.UI.WebControls;
 8 [assembly: WebResource("HBAutoCompleteTextBox.js""application/x-javascript")]
 9 namespace HBControl
10 {
11     [DefaultProperty("Text")]
12     [ToolboxData("<{0}:HBAutoCompleteTextBox runat=server></{0}:HBAutoCompleteTextBox>")]
13     public class HBAutoCompleteTextBox : TextBox
14     {
15        
16         [Bindable(true),
17         Category("Appearance"),
18         Description("备选项")
19         ]
20         public string Items
21         {
22             get 
23             {
24                 string s = (string)ViewState["Items"];
25                 return (s == null? string.Empty : s;
26             }
27             set 
28             {
29                 ViewState["Items"= value; 
30             }
31         }
32         protected override void OnPreRender(EventArgs e)
33         {
34             if (this.Page != null)
35             {
36                 ClientScriptManager mgr = this.Page.ClientScript;
37                 mgr.RegisterClientScriptResource(typeof(HBAutoCompleteTextBox), "HBAutoCompleteTextBox.js");
38             }
39             base.OnPreRender(e);
40             this.Attributes.Add("onkeyup""AutoComplete('" + this.ClientID + "','"+this.Items+"');");
41         }
42     }
43 }
44 
以上实现效果如下:
具有自动完成功能的TextBox控件
问题:
 在按回车选择的时候,总是提交页面,很郁闷,还请高手指教!现在先用左右箭头键进行选择的。

相关文章:

  • 2022-12-23
  • 2021-12-20
  • 2021-10-27
  • 2021-11-26
  • 2022-12-23
  • 2021-09-07
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-01-17
  • 2022-01-09
  • 2021-07-19
  • 2021-06-08
  • 2021-04-29
  • 2021-08-13
  • 2022-12-23
相关资源
相似解决方案