Question

My autocomplete works fine when using my old site but does not work when I ported over to C# and Entity Framework. The below HTML is part of a user control. I've put breakpoints in the webservice code and it doesn't even look like it's getting called. I don't know where else to check to see where the break is. Any help would be appreciated. Thanks.

<asp:ScriptManagerProxy ID="ScriptManagerProxy1" runat="server">
</asp:ScriptManagerProxy>
                         <asp:TextBox ID="TextBoxDamName" runat="server" Columns="50"></asp:TextBox>
                    <asp:AutoCompleteExtender ID="TextBoxDamName_AutoCompleteExtender"
                        runat="server"
                        DelimiterCharacters="" 
                        Enabled="True" 
                        ServicePath="DamSafetyAutoComplete.asmx"
                        ServiceMethod="SelectDamNames" 
                        FirstRowSelected="True" 
                        MinimumPrefixLength="1" 
                        CompletionInterval="200"
                        TargetControlID="TextBoxDamName">
                    </asp:AutoCompleteExtender></td>

namespace ExternalDamSafetySearch
{
    /// <summary>
    /// Summary description for DamSafetyAutoComplete
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    [System.Web.Script.Services.ScriptService]
    public class DamSafetyAutoComplete : System.Web.Services.WebService
    {
        [WebMethod]
        [System.Web.Script.Services.ScriptMethod]
        public string[] SelectDamNames(string prefixText, Int32 count)
        {
            try
            {
                EnterprisePubEntities EE = new EnterprisePubEntities();

                return EE.DamSafetyDatas
                    .Take(count)
                    .Where(c => c.DamName.StartsWith(prefixText))
                    .Distinct()
                    .OrderBy(c => c.DamName)
                    .Select(c => c.DamName)
                    .ToArray();
            }
            catch (Exception) { throw; }
        }
    }
}
Was it helpful?

Solution

Turns out that I wasn't directing the control to the correct locatioin for my Webservice file. Once I fixed that I still wasn't getting results even though I was hitting the method in the webservice. Turns out I wasn't return the results correctly. I fixed it by turning this

            return EE.DamSafetyDatas
                .Take(count)
                .Where(c => c.DamName.StartsWith(prefixText))
                .Distinct()
                .OrderBy(c => c.DamName)
                .Select(c => c.DamName)
                .ToArray();

to

            return EE.DamSafetyDatas
                 .Where(c => c.DamName.StartsWith(prefixText))
                .Distinct().Take(count)
                .OrderBy(c => c.DamName)
                .Select(c => c.DamName)
                .ToList.ToArray();

I also had to change the location of the .Take(count) because it would take the first (count = 10) from the list THEN filter them by starts with.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top