AutoComplete is an ASP.NET AJAX extender that can be attached to any TextBox control, and will associate that control with a popup panel to display words that begin with the prefix typed into the textbox.
The dropdown with candidate words supplied by a web service is positioned on the bottom left of the text box.
Free Download
AutoCompleteExtender Ajax Control : Demo Project
aspx Page Code:
<form id="form1" runat="server"> <div style="border-style: groove; border-width: thin; color:
#800080; width: 700px; height: 500px; background-color: #CCCCFF;">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager> <br /> <br /> <br /> Google Seach: <asp:TextBox ID="TextBox1" runat="server" Font-Bold="True" Font-Names=
"Verdana" Font-Size="10pt" ForeColor="#000066" Width="500px"></asp:TextBox>
<cc1:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server"
MinimumPrefixLength="1" TargetControlID="TextBox1" ServiceMethod=
"getList" ServicePath="google.asmx"> </cc1:AutoCompleteExtender>
<asp:Button ID="btnSubmit" runat="server" onclick="btnSubmit_Click"
Text="Search" BorderColor="#CCCCFF" Font-Bold="True"
ForeColor="#660033" /> </div> </form>
Google.asmx page code:
<%@ WebService Language="C#" Class="google" %> using System; using System.Collections.Generic; using System.Web; using System.Collections; using System.Web.Services; using System.Web.Services.Protocols; using System.Xml;
/// <summary> /// Summary description for google /// </summary> [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.Web.Script.Services.ScriptService] public class google : System.Web.Services.WebService { [WebMethod] public string[] getList(String prefixText)
{ XmlDocument doc = new XmlDocument(); List<String> suggArList = new List<string>(); string url = "http://google.com/complete/search?output=toolbar&q=" + prefixText; doc.Load(url); foreach (XmlNode node in doc.SelectNodes("//CompleteSuggestion")) { string value = node.SelectSingleNode("suggestion/@data").InnerText; suggArList.Add(value); } return suggArList.ToArray(); } }