Ajax AutoCompleteExtender (Without WebService) Not Working [Resolved]

Posted by Sharpcnet under ASP.NET AJAX on 11/26/2013 | Points: 10 | Views : 2958 | Status : [Member] | Replies : 3
I'm trying to use the Ajax AutoCompleteExtender, but it's not working. Where am I going wrong. Other Ajax controls like update panel, are working fine. Using EntityFramework, C#,Chrome.

ASPX:
<asp:TextBox ID = "txtSearch" runat="server">
<ajax:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server"
TargetControlID="txtSearch" MinimumPrefixLength="2" EnableCaching="true"
CompletionSetCount="10" CompletionInterval="1000" ServiceMethod="GetCountries">
</ajax:AutoCompleteExtender>
ASPX.CS
[System.Web.Script.Services.ScriptMethod()]
[System.Web.Services.WebMethod]

public static IEnumerable<string> GetCountries()
{
return objDAL.GetCountries(txtSearch.Text.Trim());
}
DAL:
public IEnumerable<string> GetCountries(string text)
{
return MyDB.tblCountries.Where(e=>e.CountryName.StartsWith(text)).
Select(e=>e.CountryName);
}
Also tried
public static List<string> GetCountries()
{
return objDAL.GetCountries(txtSearch.Text.Trim()).ToList();
}





Responses

Posted by: Allemahesh on: 11/26/2013 [Member] [MVP] Silver | Points: 50

Up
0
Down

Resolved
Right, you got it.

See the below one:-

<ajax:ToolkitScriptManager ID="ScriptManager1" runat="server" />
<div>
<asp:TextBox ID="txtSearch" runat="server"></asp:TextBox>
<ajax:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" TargetControlID="txtSearch"
MinimumPrefixLength="1" EnableCaching="true" CompletionSetCount="1" CompletionInterval="1000"
ServiceMethod="GetData">
</ajax:AutoCompleteExtender>
</div>


[System.Web.Script.Services.ScriptMethod()]
[System.Web.Services.WebMethod]
public static List <string> GetData(string prefixText)
{

}


Happy Coding,
If it helps you or directs U towards the solution, MARK IT AS ANSWER

Sharpcnet, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Allemahesh on: 11/26/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
Dear Sharpcnet,

I have see your code. AutoCompleteExtender will work with entity framework also.

Just change your code as below:-

<ajax:ToolkitScriptManager ID="ScriptManager1" runat="server" />
<div>
<asp:TextBox ID="txtSearch" runat="server"></asp:TextBox>
<ajax:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" TargetControlID="txtSearch"
MinimumPrefixLength="0" EnableCaching="true" CompletionSetCount="10" CompletionInterval="1000"
ServiceMethod="GetData">
</ajax:AutoCompleteExtender>
</div>


[System.Web.Script.Services.ScriptMethod()]
[System.Web.Services.WebMethod]
public static List<string> GetData()
{
//Your code
}


Note:- Make sure the you have added below line of code in your page.

<ajax:ToolkitScriptManager ID="ScriptManager1" runat="server" />

Please let me know if you have issue.

Happy Coding,
If it helps you or directs U towards the solution, MARK IT AS ANSWER

Sharpcnet, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sharpcnet on: 11/26/2013 [Member] Starter | Points: 25

Up
0
Down
The parameter for the string has to be mentioned and also with the exact name.

GetData(string prefixText)

Sharpcnet, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response