Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Ajax AutoCompleteExtender not working in SharePoint web part.

45 views
Skip to first unread message

Pat

unread,
Oct 9, 2009, 7:54:01 PM10/9/09
to
I use AjaxControlToolkit's 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, which has Ajax feature. That is the ScriptManager exists on the
sharepoint page. The web part has these code:

using AjaxControlToolkit;

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 = "Just testing";
this.Controls.Add(autoComplete);
}

2. The web service file AutoCompleteWebService.asmx inside the same project
as step 1 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 displayed on the sharepoint page. I have
checked that 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.

Stock

Chris Givens

unread,
Oct 9, 2009, 9:41:01 PM10/9/09
to
Hi Pat,

You can reference my AJAX lab and see if there may be anything you might
have missed in your deployment.

http://cbt.architectingconnectedsystems.com/50064/50064%20_Module_14.htm

Chris

"Pat" <Pa...@newsgroups.nospam> wrote in message
news:3A41247B-F63F-4847...@microsoft.com...

Pat

unread,
Oct 12, 2009, 3:56:01 PM10/12/09
to
Now, I found out it is the path problem. I used WSPBuilder to add a web
service (AutoCompleteWebService.asmx) and build the web part. When making
deployment to the production box, AutoCompleteWebService.asmx will be placed
to the SharePoint directory ../12/TEMPLATE/LAYOUTS/. On my web part, if the
AutoCompleteExtender has this path: string webServicePath =
"../12/TEMPLATE/LAYOUTS/AutoCompleteWebService.asmx";, the web service will
not work, which return a lot of "undefined". Now, if I copy the
AutoCompleteWebService.asmx to the directory wss\VirtualDirectories\80\, and
change the path to: string webServicePath =
"http://ServerName:80/AutoCompleteWebService.asmx";, the web service works
fine.

So, the question to you is: how do you deploy customized web service to the
SharePoint production box? Do you use a tool such as WSPBuilder, or manually
copy and paste?

Thanks

Pat

0 new messages