0

I wan to use an AjaxToolkit AutoCompleteExtender. My WebService is triggered and, if I put a breakpoint on the returned value, I can see there is data being returned. But, AutoCompleteExtender is not displaying the results.

I've read this stackoverflow thread: AutoCompleteExtender is firing, webservice is returning results, but these are not being displayed

But, that answer does not solve the issue I'm having.

Here's my code:

ASPX

<asp:ToolkitScriptManager ID="asm" runat="server" EnablePageMethods="true" EnablePartialRendering="true"></asp:ToolkitScriptManager>
<asp:UpdatePanel ID="upApprovedBy" runat="server">
    <ContentTemplate>
        <asp:TextBox id="txtApprovedBy" runat="server" AutoComplete="Off"></asp:TextBox>
        <asp:AutoCompleteExtender 
            runat="server" 
            ID="ac_txtApprovedBy"  
            CompletionInterval="500"
            TargetControlID="txtApprovedBy"
            ServiceMethod="SearchWinUsers"
            CompletionSetCount="20"                                                                                                                         
            MinimumPrefixLength="2" 
        >
        </asp:AutoCompleteExtender>
    </ContentTemplate>
</asp:UpdatePanel>

ASPX.CS

[System.Web.Script.Services.ScriptMethod()]
[System.Web.Services.WebMethod]
public static string[] SearchWinUsers(string prefixText, int count)
{
    logic common = new logic();
    string[] SelectedApprovers = new string[0];
    try
    {
        DataTable dt = new DataTable();
        string sql = "SELECT TOP(" + count + ") FirstName + ' ' + LastName AS DisplayName FROM USERSTABLENAME WHERE (IsDeActivated = 0) AND ((FirstName LIKE '%" + prefixText + "%') OR (LastName LIKE '%" + prefixText + "%')) ORDER BY FirstName";
        dt = common.getDataTable(sql);
        SelectedApprovers = new string[dt.Rows.Count];
        int i = 0;
        foreach (DataRow dr in dt.Rows)
        {
            SelectedApprovers.SetValue(dr["DisplayName"].ToString(), i);
            i++;
        }
        dt.Dispose();
    }
    catch (Exception ex)
    {
        common.alert("Error in page.location.<br>ERROR=" + ex.Message);
    }

    return SelectedApprovers;
}

Any suggestions would be appreciated!

I should mention that the code in my ASPX snippet lives in this hierarchy: Page > TabContainer > TabPanel > FormView > THIS CODE LIVES HERE

Community
  • 1
  • 1
s15199d
  • 7,261
  • 11
  • 43
  • 70
  • Have you tried removing the `UpdatePanel` from around your `AutoCompleteExtender`? You don't need that to make the Extender async. – Josh Darnell Jul 03 '12 at 19:23
  • I removed the UpdatePanel. Same outcome. The WebService is called. SelectedApprovers has data in it on the return line of code. Still nothing is displayed on the front end. Thanks anyway jadarnel27. – s15199d Jul 03 '12 at 19:55
  • No problem, worth a shot I guess. – Josh Darnell Jul 03 '12 at 20:06

1 Answers1

0

Got it to work finally!!!

I moved the webservice out of the *.ASPX.CS to an *.ASMX

That resolved the issue I was having.

If you're having the same problem, checkout this tutorial. It got me going in the right direction!

http://www.codeproject.com/Articles/201099/AutoComplete-With-DataBase-and-AjaxControlToolkit#

s15199d
  • 7,261
  • 11
  • 43
  • 70
  • Ok, I put all my web service in asmx file. but now the issue I was facing is when I deploy my web on localhost, my autocompleteextender not working. It's not showing me the result. Although service is working perfectly in my development environment. Can you help me on this? Did you deploy you web app on localhost and try to use autocompleteextender and its work fine? Please let me know. – Ahmer Ali Ahsan Jan 29 '19 at 11:10