I am trying to implement the autocomplte example on http://www.aspsnippets.com/Articles/AJAX-AutoCompleteExtender-Example-in-ASPNet.aspx to my own web page.
Author says;
Here I am explaining, how to use AJAX AutoCompleteExtender Control directly with ASP.Net Web Page without using any web service.
I have
- downloaded AjaxControlToolkit
- installed the toolikt
- written the code according to my own aim.
My code is as the following:
<!--Default.aspx-->
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
...
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
</asp:ScriptManager>
...
<asp:TextBox ID="txt_searchTerm" runat="server"></asp:TextBox>
<cc1:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server"
CompletionInterval="200" MinimumPrefixLength="4" EnableCaching="false"
CompletionSetCount="10" TargetControlID="txt_searchTerm"
FirstRowSelected="false" ServiceMethod="searchInDictionary">
</cc1:AutoCompleteExtender>
//Default.aspx.cs
[System.Web.Script.Services.ScriptMethod()]
[System.Web.Services.WebMethod]
public static List<string> searchInDictionary(string prefixText, int count)
{
using (OleDbConnection conn = new OleDbConnection())
{
conn.ConnectionString = ConfigurationManager
.ConnectionStrings["myConnectionString"].ConnectionString;
using (OleDbCommand cmd = new OleDbCommand())
{
cmd.CommandText = "SELECT word FROM Dictionary WHERE word LIKE @searchTerm + '%'";
cmd.Parameters.AddWithValue("@searchTerm", prefixText);
cmd.Connection = conn;
conn.Open();
List<string> result = new List<string>();
using (OleDbDataReader dr = cmd.ExecuteReader())
{
while (dr.Read())
{
result.Add(dr["word"].ToString());
}
}
conn.Close();
return result;
}
}
After typing 4 characters into the textbox I get a list which holds too many chacarters that are the current page's html source. There is only one character of the source code on each line. It is like
<
!
D
O
C
T
Y
P
E
...
till
<
/
h
t
m
l
>
I am trying to autocomplete the word "Cancer". I type "canc" and it lists HTML source.
I have inspected the page using FireBug In the XHR section of Net tab, a POST action fires and the values are below:
JSON
count 10
prefixText "canc"
Source
{"prefixText":"canc","count":10}