Click here to Skip to main content
15,911,531 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
can anyone help me, i'd been stuck in this for many hours.

i took a textbox and apply auto complete extender to it and create a web service, but the thing is when i am running application text box not displaying result, although my web services fetch the result when i am web service. Can anyone help me?

Here is my html code

ASP.NET
<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


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

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

/// <summary>
/// Summary description for MyService
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// 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 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();
        }
    }
}
Posted

1 solution

Quote:
Note that you can replace "GetCompletionList" with a name of your choice, but the return type and parameter name and type must exactly match, including case.

try below
C#
[System.Web.Script.Services.ScriptMethod()]
[System.Web.Services.WebMethod]
public static string[] ReturnTerritory(string prefixText, int count)
{
        using (NovartisModel.NovartisEntities cntxt = new NovartisModel.NovartisEntities())
        {
            var res = from q in cntxt.tblTerritory where q.Territory_Name.ToLower().StartsWith(prefixText.ToLower()) select q.Territory_Name;
            List<string> responses = new List<string>();
            foreach(string item in res)
            {
                responses.Add(item);
            }
            return responses.ToArray();
        }
}
 
Share this answer
 
v2
Comments
Muhammad Bilal Khan 27-Dec-14 12:13pm    
thanks #DamithSl but it is still not working

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900