AJAX Autocomplete:
Default.aspx
Add reference to the Ajaxcontroltoolkit on the page as shown below,
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
Now add a ScriptManager(old version) or ToolkitScriptManager(new version) in the <form> tag,
The body of page should contain a Textbox to input values and then drop in an AJAX AutoCompleteExtender from the Toolbox.
<div>
<asp:TextBox ID="txtSearch" runat="server"></asp:TextBox>
<asp:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" TargetControlID="txtSearch"
ServicePath="~/Autocomplete.asmx" ServiceMethod="GetBooks" MinimumPrefixLength="1"
CompletionSetCount="10">
</asp:AutoCompleteExtender>
</div>
Autocomplete.asmx
[WebMethod]
public string[] GetBooks(string prefixText, int count)
{
if (count == 0)
{
count = 10;
}
if (prefixText.Equals(" "))
{
return new string[0];
}
List<string> books = new List<string>(count);
books.Add("ASP.NET");
books.Add("C#.NET");
books.Add("The fallen Angel");
books.Add("Seed");
books.Add("The communist");
books.Add("A wanted man");
return books.ToArray();
}
Default.aspx
Add reference to the Ajaxcontroltoolkit on the page as shown below,
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
Now add a ScriptManager(old version) or ToolkitScriptManager(new version) in the <form> tag,
The body of page should contain a Textbox to input values and then drop in an AJAX AutoCompleteExtender from the Toolbox.
<div>
<asp:TextBox ID="txtSearch" runat="server"></asp:TextBox>
<asp:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" TargetControlID="txtSearch"
ServicePath="~/Autocomplete.asmx" ServiceMethod="GetBooks" MinimumPrefixLength="1"
CompletionSetCount="10">
</asp:AutoCompleteExtender>
</div>
Autocomplete.asmx
[WebMethod]
public string[] GetBooks(string prefixText, int count)
{
if (count == 0)
{
count = 10;
}
if (prefixText.Equals(" "))
{
return new string[0];
}
List<string> books = new List<string>(count);
books.Add("ASP.NET");
books.Add("C#.NET");
books.Add("The fallen Angel");
books.Add("Seed");
books.Add("The communist");
books.Add("A wanted man");
return books.ToArray();
}