I can't get AJAX CT Autocomplete to work. The problem is when I start writing in textbox nothing happens. The frist problem I had experienced was when I tried to Add AutoComplete page method I got an error: "Cannot create page method "GetCompletionList"...". Then I tried creating it manually, but still nothing happens.
Here is the AdministracijaOsoba.aspx code:
<asp:TextBox ID="txtOsoba" runat="server"></asp:TextBox><asp:AutoCompleteExtender
ID="AutoCompleteExtender1" runat="server" ScriptPath=""
ServiceMethod="GetCompletionList" ServicePath="AdministracijaOsoba.aspx.cs"
TargetControlID="txtOsoba" UseContextKey="True">
</asp:AutoCompleteExtender>
Here is the AdministracijaOsoba.aspx.cs code:
public static string[] GetCompletionList(string prefixText, int count, string contextKey)
{
PravosudnaAkademijaEntities db = new PravosudnaAkademijaEntities();
var osoba = from o in db.osobas
orderby o.osoba_prezime
select new { o.osoba_id, person = o.osoba_prezime + " " + o.osoba_ime };
string[] main = new string[0];
foreach (var o in osoba)
{
if (o.person.StartsWith(prefixText))
{
Array.Resize(ref main, main.Length + 1);
main[main.Length - 1] = o.person.ToString();
if (main.Length == 15)
{
break;
}
}
}
Array.Sort(main);
return main;
}
Take a note that I'm using LINQ to Entities. Any help on this would be appreciated.
Regards!
Your code behind should read like this
[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]
public static string[] GetCompletionList prefixText, int count, string contextKey)
{....}
Also, there is no need of providing the servicepath attribute for your ajax extender if you are using a pagescriptmethod.