Click here to Skip to main content
15,905,144 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to use autocomplete extender in my web application .for this i make a web service in my current web application and add web reference in the application .But its not working .
Can anyh one help me.please
Posted
Comments
Kiran Sonawane 3-Jun-11 0:57am    
Can you show your code (web method) and aspx code of autocomplete
Sandeep Mewara 3-Jun-11 1:05am    
You have to be more elaborate than 'its not working'. Further, a small related code snippets of the layers would surely help.
thatraja 3-Jun-11 1:25am    
Any error? if yes then include that in your question.

1 solution

Ok, step 1:

Make your WebService. In your project, create a folder called Services, (not a necessity, but neat :P) Right click and say Add -> New Web Service. Lets call it WSAutoComplete. Now make it look like this:

C#
namespace Services
{
    /// <summary>
    /// Summary description for WSAutoComplete
    /// </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 WSAutoComplete : System.Web.Services.WebService
    {
        [WebMethod]
        [ScriptMethod]
        public string[] GetAutoCompleteList(string prefixText, int count)
        {
            return GetResults(prefixText, count);
        }
    }

    private string[] GetResults(prefixText, count)
    {
         //Do your logic here
         //Example
         List<string> items = new List<string>() {"bob", "steve", "jones", "andrew"};
         List<string> result = new List<string();>
         foreach (string s in items)
             if (s.StartsWith(prefixText))
                 result.Add(s);
         return result.ToArray();
    }</string></string></string>
(Ignore this </string></string></string>, I dont know why thats there being generated by the text editor???)

I purposely left out the count for time purposes, you can add that yourself, just limit the amount of results that you return.

Now, on you AutoCompleteExtender control:

XML
<asp:TextBox id="txtMyTextBox" runat="server"></asp:TextBox>
<asp:AutoCompleteExtender TargetControlID="txtMyTextBox" ServicePath="/Services/WSAutoComplete.asmx"CompletionInterval="500" MinimumPrefixLength="2" ServiceMethod="GetResults"
ID="autocomplete" runat="server"></asp:AutoCompleteExtender>


That should work 100%!!! Make sure you set up your service path correctly! Put a break point inside you service method and see if it gets hit! If it doesnt, then there is probably a problem with your ServicePath or ServiceMethod paramter
 
Share this answer
 
v4

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