Creating Sharepoint Web Parts that use the Ajax Control Toolkit

Topics: Developer Forum
Feb 12, 2007 at 3:43 AM
I have installed the Sharepoint AJAX Toolkit and have added the XML web part to my site.

Now I would like to create a custom Web Part that encapsulates the Ajax Control Toolkit - Collapsible Panel control. How do I go about doing this? I tried referencing AjaxControlToolkit.dll and creating a new CollapsiblePanel control, though I get an error after I add the web part to the site.
Feb 21, 2007 at 1:43 PM
I also would like some instruction on how to incorporate the AJAX ToolKit into SharePoint using the SharePoint AJAX Toolkit.

Regards,

John P. Grieb
Mar 4, 2007 at 5:23 AM
John and Blake,

The Ajax Control Toolkit may not be fully compatible with WSS. This project DOES NOT provide any support for working with that toolkit, but instead provides a base framework for deploying client-side AJAX controls that work against web services and Xml feeds.

What you MAY want to do is pull out some of the client side code from that toolkit and deploy them in your own script libraries. This project is also open to contribution, so if you have useful AJAX code you'd like to submit to the project let me know!

Daniel Larson

I hope that helps!
Mar 8, 2007 at 6:25 AM
I went with Daniel's suggestion to pull out the code from the Ajax Control Toolkit and implemented it within a Web Part that I am using on a Sharepoint site. This is what I did:

1. Installed the Sharepoint AJAX Toolkit on the site.
2. Created a Web Part. I have created a new Search Box Web Part, that looks like the regular Sharepoint 2007 SearchBoxEx, and in addition provides Google Suggest type functionality.
3. I wanted to use the AutoComplete Extender from the Ajax Control Toolkit, so I copied all the code out of the AutoComplete folder and put it into my web part project.
4. Determined all the other code I would need by compiling, finding missing references, and adding more code files from the Ajax Control Toolkit as needed. Many common files were needed. Note that you need to set any .JS files to EmbeddedResources.
5. This enabled the code to run. This may be enough for many of the controls.
6. The AutoComplete control requires getting data from a Web Service. I built a web service that uses the MOSS 2007 Search API to return a list of results. This web service had to be hosted within the same Web Site (same port) as the Sharepoint site itself. Needed to grant CAS trust for the Web Service assembly as a result.

7. That's it. The search box works well and returns a suggestion list quick enough to be useful. I look forward to seeing how fast it will run in a test environment with more users/load.

I have pointed out the main steps and gotchas. Daniel if you would like a source code contribution and more detailed steps, please let me know.
Apr 27, 2007 at 8:29 PM
Dear Blake,

II am trying to do the same thing, but am very new to both ASP.NET and SharePoint. Would you be willing to post more detailed instructions or some of your Search Box Web Part code?

Thanks for your help,
Juanita
May 14, 2007 at 1:44 PM
Hi Blake

Can you provide me the source code or detailed step to do this. That will more helpfull ffor me.

Regards
Vivek.T


Blake wrote:
I went with Daniel's suggestion to pull out the code from the Ajax Control Toolkit and implemented it within a Web Part that I am using on a Sharepoint site. This is what I did:

1. Installed the Sharepoint AJAX Toolkit on the site.
2. Created a Web Part. I have created a new Search Box Web Part, that looks like the regular Sharepoint 2007 SearchBoxEx, and in addition provides Google Suggest type functionality.
3. I wanted to use the AutoComplete Extender from the Ajax Control Toolkit, so I copied all the code out of the AutoComplete folder and put it into my web part project.
4. Determined all the other code I would need by compiling, finding missing references, and adding more code files from the Ajax Control Toolkit as needed. Many common files were needed. Note that you need to set any .JS files to EmbeddedResources.
5. This enabled the code to run. This may be enough for many of the controls.
6. The AutoComplete control requires getting data from a Web Service. I built a web service that uses the MOSS 2007 Search API to return a list of results. This web service had to be hosted within the same Web Site (same port) as the Sharepoint site itself. Needed to grant CAS trust for the Web Service assembly as a result.

7. That's it. The search box works well and returns a suggestion list quick enough to be useful. I look forward to seeing how fast it will run in a test environment with more users/load.

I have pointed out the main steps and gotchas. Daniel if you would like a source code contribution and more detailed steps, please let me know.

Jul 4, 2008 at 12:11 PM
@Blake:

Can you please share the code of the Autocomplete thing you have done.

Since I am working on an autocomplete textbox that brings values from a database and I have created a user control for this. This user control is working fine but when I implement it inside a web part and try to run it, it gives me access denied error when i enter any character in the textbox. Can you please let me know how did you achieve this and also share the code with me.

P.S. I also used the Smart Part (available on Codeplex) to host the user control but the same error is occuring.
Jul 14, 2008 at 1:13 PM
Hi Blake,

Can you please share the code for implementating google suggest functionality on moss ?
Aug 23, 2009 at 12:24 PM

hi Blake,

can you pls share the code of the Ajax Autocomplete thing 

Jan 14, 2010 at 9:13 AM

Hi I have problem with "AutoCompleteExtender"...

here is my webservice code....

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Script.Services;
using System.Data;
using Microsoft.Office.Server.Search.Query;
using Microsoft.SharePoint;

namespace AutocompleteSearchWebService
{
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    [System.Web.Script.Services.ScriptService]

    // 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 AutoCompleteSearchWS : System.Web.Services.WebService
    {

        [WebMethod]
        [System.Web.Script.Services.ScriptMethod]
        public System.Collections.Generic.List<string> HintSearch(string prefixText)
        {
            try
            {
                using (SPSite siteCollection = SPContext.Current.Site)
                {
                    FullTextSqlQuery query = new FullTextSqlQuery(siteCollection);
                    query.StartRow = 0;
                    query.HighlightedSentenceCount = 3;
                    query.EnableStemming = true;
                    query.TrimDuplicates = false;
                    query.KeywordInclusion = KeywordInclusion.AllKeywords;
                    query.QueryText = string.Format("SELECT Title FROM SCOPE() WHERE FREETEXT(defaultproperties, '{0}*') AND \"Scope\"='All Sites' ", prefixText);
                    query.ResultTypes = ResultType.RelevantResults;
                    query.RowLimit = 10;
                    ResultTableCollection queryResults = query.Execute();
                    ResultTable queryResultsTable = queryResults[ResultType.RelevantResults];
                    DataTable dt = new DataTable();
                    dt.Load(queryResultsTable, LoadOption.OverwriteChanges);
                    System.Collections.Generic.List<string> searchResult = new System.Collections.Generic.List<string>();
                    foreach (DataRow row in dt.Rows)
                    {
                        searchResult.Add(row[0].ToString());
                    }
                    return searchResult;

                }
            }
            catch (Exception)
            {
                throw new Exception("Error from Auto Complete WebService");
            }
 
        }
    }
}

 

 

Here is my Webpart code....

 

using System;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Serialization;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;
using AjaxControlToolkit;

namespace HintSearchWebpart
{
    [Guid("137b2bde-2d16-488a-8883-2134bd059705")]
    public class HintSearch : System.Web.UI.WebControls.WebParts.WebPart
    {
        public HintSearch()
        {
        }

         protected override void CreateChildControls()
        {
            try
            {
               
                TextBox textbox = new TextBox();
                textbox.AutoCompleteType = AutoCompleteType.Search;
                textbox.ID = "txtSearch";
                this.Controls.Add(textbox);
                AutoCompleteExtender autoComplete = new AutoCompleteExtender();
                autoComplete.ID = "autosearch";
                autoComplete.MinimumPrefixLength = 1;
                autoComplete.ServicePath = "~/_vti_bin/AutoCompleteSearchWS.asmx"; ;
                autoComplete.ServiceMethod = "HintSearch";
                autoComplete.TargetControlID = "txtSearch";
                this.Controls.Add(autoComplete);
            }
            catch(Exception ex)
            {
                Label errMsg = new Label();
                errMsg.Text = ex.Message;
                this.Controls.Add(errMsg);
            }
            }
        }
    }

 I have added Ajaxtoolkit reference in web.config file of Sharepoint site, and Script manager to MasterPage, wheh I am trying to add webpart to any page, I am getting error page, I am not able to add the webpart, redirecting to webpart maintenece page, but in webpart if I am commenting the "AutoCompleteExtender" my webpart works fine, could anybody help me in this....

 

Thanks in advance,

Rahamath

Jan 15, 2010 at 10:14 PM

Hey Rahamath

This toolkit is for CLIENT SIDE AJAX-- it doesn't address anything with the Ajax Control Toolkit, which is really a server-side approach to AJAX. There are many client-side autocomplete solutions you can use if you're doing client-side code.

Mar 19, 2010 at 5:25 AM

i am using asp.net 3.5, ajax and moss2007.Created web parts .but when we select value in drop down  busy image of ajax not display and drop down 

Disappear after grid fill again dropdown appear. and its not display any error. thanks