AutoCompleteExtender does not work in SharePoint web part

Topics: Developer Forum
Oct 1, 2009 at 8:22 PM

Hi,

I use AutoCompleteExtender in SharePoint (SP) web part project. Here is the details:

1. I use WSPBuilder (http://www.codeplex.com/wspbuilder) to build my SP web part. The web part has Ajax feature. That is ScriptManager exists on the sharepoint page. In the CreateChildControls method of the web part, I have these code:

private AutoCompleteExtender autoComplete = new AutoCompleteExtender();

private TextBox TB_SearchSubject = new TextBox();

protected override void CreateChildControls()

{

                    base.CreateChildControls();

                    TB_SearchSubject.ID = "TB_SearchSubject";

                    TB_SearchSubject.Width = 120;

                    this.Controls.Add(TB_SearchSubject);

                    System.Web.UI.HtmlControls.HtmlGenericControl div = new System.Web.UI.HtmlControls.HtmlGenericControl();

                    div.ID = "ListPlacement";

                    div.Attributes["style"] = "height:300px; overflow-y:scroll;";

                    this.Controls.Add(div);

 

                    autoComplete.ID = "AutoComplete1";

                    autoComplete.MinimumPrefixLength = 1;

                    autoComplete.CompletionSetCount = 20;

                    autoComplete.CompletionInterval = 1000;

                    autoComplete.DelimiterCharacters = ";, :";

                    autoComplete.CompletionListElementID = "ListPlacement";

                    autoComplete.EnableCaching = true;

                    autoComplete.ServicePath = "../12/TEMPLATE/LAYOUTS/AutoCompleteWebService.asmx";

                    autoComplete.ServiceMethod = "GetSubjects";

                    autoComplete.TargetControlID = "TB_SearchSubject";

                    //autoComplete.ContextKey = "SubjectID|CLL";

                    this.Controls.Add(autoComplete);  

}

 

2. The web service file AutoCompleteWebService.asmx has this code:

 

[WebService(Namespace = "http://tempuri.org/")]

    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

    [System.Web.Script.Services.ScriptService]

    public class AutoCompleteWebService : System.Web.Services.WebService

    {

       

        [System.Web.Services.WebMethod]

        [System.Web.Script.Services.ScriptMethod]

        public string[] GetSubjects(string prefixText, int count, string contextKey)

        {

 

            if (count == 0)

            {

                count = 10;

            }

 

            List<string> items = new List<string>(count);

 

            ArrayList arr_test = new ArrayList();

            arr_test.Add("ab");

            arr_test.Add("kg");

            arr_test.Add("iq");

            arr_test.Add("le");

            arr_test.Add("cd");

 

            for (int i = 0; i < arr_test.Count; i++)

            {

                items.Add(AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(arr_test[i].ToString(), arr_test[i].ToString()));

            }

           

            return items.ToArray();

        }

 

}

 

3. Now, I build and deploy WSP file to the SharePoint server in my dev box. Deployment is OK. The web part is also available on the sharepoint page. I have checked the file AutoCompleteWebService.asmx indeeds locates at ../12/ TEMPLATE/LAYOUTS/AutoCompleteWebService.asmx.

 

Now, I enter “a” to the text box, a list of “undefined” appears (all the items are “undefined”). If everything worked, “ab” should be displayed as I have “ab” item in the ArrayList (see the code above).

 

4. If I place the AutoCompleteExtender to a normal ASP.NET app and the web service asmx file exactly has the same code as above, it works and “ab” is shown.

 

So, what things go wrong in the SharePoint web part?

 

If you know what problem is, could you make comment about it? Thanks.