2

I took a text box and applied auto complete extender to it to create a web service, but when it runs, the application text box is not displaying the result although my web service fetches the result.

Here is my HTML code:

<asp:UpdatePanel ID="UpdtPanel" runat="server">
<ContentTemplate>
<asp:TextBox ID="txtTerri" runat="server"></asp:TextBox>
<asp:AutoCompleteExtender ID="txtTerri_AutoCompleteExtender" runat="server"                        
TargetControlID="txtTerri"
ServiceMethod="ReturnTerritory" ServicePath="~/MyService.asmx" 
MinimumPrefixLength="1" EnableCaching="true"
CompletionInterval="1000" CompletionSetCount="10" 
CompletionListCssClass="autocomplete_completionListElement " 
CompletionListHighlightedItemCssClass="autocomplete_highlightedListItem" 
CompletionListItemCssClass="autocomplete_listItem">
</asp:AutoCompleteExtender>
</ContentTemplate>
</asp:UpdatePanel>

Here is my CSS:

.autocomplete_completionListElement 
{  
 visibility : hidden;
 margin : 0px!important;
 background-color : inherit;
 color : windowtext;
 border : buttonshadow;
 border-width : 1px;
 border-style : solid;
 cursor : 'default';
 overflow : auto;
 height : 200px;
 text-align : left; 
 list-style-type : none;
}
.autocomplete_listItem 
{
 z-index: 9999 !important;
 background-color : window;
 color : windowtext;
 padding : 1px
}

.autocomplete_highlightedListItem
{
 background-color: #ffff99;
 color: black;
 padding: 1px;
}

Here is my web service:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Configuration;
using System.Web.UI.WebControls;

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService()]
public class MyService : System.Web.Services.WebService {
    public MyService()
    {
        //Uncomment the following line if using designed components 
        //InitializeComponent(); 
    }

    [WebMethod]
    public string[] ReturnTerritory(string prefix, int count)
    {
        using (NovartisModel.NovartisEntities cntxt = new NovartisModel.NovartisEntities())
        {
            var res = from q in cntxt.tblTerritory where q.Territory_Name.ToLower().StartsWith(prefix.ToLower()) select q.Territory_Name;
            List<string> responses = new List<string>();
            foreach(string item in res)
            {
                responses.Add(item);
            }
            return responses.ToArray();
        }
    }
}
BartoszKP
  • 34,786
  • 15
  • 102
  • 130

1 Answers1

0

Have you tried returning the WebMethod as List() ?

I believe it expects a list of string instead of a string array.

[WebMethod()]
public list<string> ReturnTerritory(string prefix, int count)
{
    ...
}
bergerb
  • 96
  • 2
  • 2