Pages

Sunday, August 29, 2010

Ajax Control Toolkit with SharePoint 2010

I had to use Ajax control toolkit with sharepoint and I had download the latest version from codeplex. We usually download latest versions of software because we believe that with latest version we can get more features and more bug-free. I had used Ajax Control Toolkit with SharePoint 2007 and it was much easier to configure and use Ajax Control Toolkit. With that belief in mind I had started using Ajax Control Toolkit in SharePoint 2010 downloading latest version for .net framework 3.5. But I failed  and after investigating I had found the following errors.

  • AjaxControlToolkit requires ASP.NET Ajax 4.0 scripts. Ensure the correct version of the scripts are referenced. If you are using an ASP.NET ScriptManager, switch to the ToolkitScriptManager in AjaxControlToolkit.dll.
  • Sys.registerComponent is not a function


The problem here is that latest versions of Ajax Control Toolkit is more optimized or targeted with .net framework 4.0. Even the Ajax control toolkit for .net framework 3.5 doesn’t work with SharePoint 2010. If you try to use Ajax Control Toolkit for 3.5 with SharePoint 2010, you may get the exceptions shown above.

How to make Ajax Control Toolkit working with SharePoint 2010?

Here are the steps to make Ajax Control Toolkit working with SharePoint 2010.

  1. Download Correct (compatible) version of Ajax Control Toolkit.

    Since current release of Ajax Control Toolkit doesn’t work with SharePoint 2010, you need to download previous release. Maybe Ajax Control Toolkit team will address this issue and we’ll be able to use current Toolkit version with SharePoint in future. Until the current release is made compatible, please download the SharePoint 2010 compatible Ajax Control Toolkit from here.

  2. Add AjaxControlToolkit.dll reference to your project

    To use the Ajax Control Toolkit in your SharePoint project, add reference to the AjaxControlToolkit.dll in your project. To use the Ajax Control Toolkit in any web part control add the following lines to register the Ajax Control Toolkit namespace.

    <%@ Register Assembly="AjaxControlToolkit, Version=3.0.30930.28736,
    Culture=neutral,
    PublicKeyToken=28f01b0e84b6d53e"
    Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
  3. Remember, here version 3.x version of Ajax Control Toolkit is used instead 3.5.

  4. Add Ajax Control Toolkit ScriptManager in master page.

    Open the Master page in SharePoint Designer. By default the v4.Master file is the default master page can be found “_catalogs/masterpage” folder. Before modifying the master page, keep a backup copy.

    • First register the Ajax Control Toolkit namespace in the masterpage file by putting the following line at the top of the file:
      <%@ Register Assembly="AjaxControlToolkit, Version=3.0.30930.28736,
      Culture=neutral, PublicKeyToken=28f01b0e84b6d53e"

      Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
    • Then remove the ScriptManager registration from the master page by removing the following line:
      <asp:ScriptManager id="ScriptManager" runat="server" EnablePageMethods="false"  
      EnablePartialRendering="true" EnableScriptGlobalization="false" EnableScriptLocalization="true"/>
    • Finally Add the following line in place of the above line to register Ajax Control Toolkit
      <ajaxToolkit:ToolkitScriptManager id="ScriptManager" runat="server" EnablePageMethods="false" 
      EnablePartialRendering="true" EnableScriptGlobalization="false" EnableScriptLocalization="true"/>
  5. Register Ajax Control Toolkit namespaces in SharePoint package Designer 

    Finally, you need to register the Ajax Control Toolkit namespace with SharePoint Package designer. Registering Ajax Control Toolkit namespaces will add Ajax Control Toolkit namespaces in web.config’s safecontrol list. First open the Package designer in Visual Studio (Package usually exists under Package folder in Visual Studio). And then click the “Advanced” button in package designer window as shown in the image below. In that advanced tab you can add/edit assemblies to be registered safe as part of the deployment of the solution package. Click Add ==> “Add Existing Assembly”. The following image shows wizard to follow.

    image

    Figure 1: Package Designer’s Advance tab

    In the “Add existing Assembly” window, add the following namespaces for Ajax Control Toolkit.

    Namespace Type Name Assembly Name
    AjaxControlToolkit * AjaxControlToolkit
    AjaxControlToolkit.Design * AjaxControlToolkit
    AjaxControlToolkit.HTMLEditor * AjaxControlToolkit
    AjaxControlToolkit.HTMLEditor.Popups * AjaxControlToolkit
    AjaxControlToolkit.HTMLEditor.ToolbarButton * AjaxControlToolkit
    AjaxControlToolkit.MaskedEditValidatorCompatibility * AjaxControlToolkit

    The following image shows the “Add Existing Assembly” window for AjaxControlToolkit dll.

    image

    Figure 2: Add/Edit Existing Assembly window

    Now you can build and deploy the package and as a result of deployment, Ajax Control Toolkit namespaces will be registered as safe controls in web.config.

Conclusion

Its really hard to believe that Ajax Control Toolkit’s  latest version doesn’t work with SharePoint. We expect to have the latest version of Ajax Control Toolkit to be compatible with SharePoint 2010. Until then we might have to use an old version of Ajax Control Toolkit.

40 comments:

  1. Thanks for this great information. I was searching for this information 2-3 months back and gave on using Ajax control toolkit with SP2010.
    After reading this I am thinking of utilizing Ajax contol toolkit but I have a question before that:
    --> Replacement of registration with in master page will it break the normal SP2010 Out-of-the-box Ajax functionalties or the ajax functionalties I implemented in my custom webpart(basic ajax functions like async update etc.).

    ReplyDelete
  2. Registering the ajaxcontroltoolkit scriptmanager in master page will not break other pages as this scriptmanager is inherited from the asp.net ajax's scriptmanager.

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. This Blog is Ow-some.It really works thanks Sohel.
    Some good sharepoint topics are also available at http://krutingandhi.blogspot.com

    ReplyDelete
  5. What file are you refering to put those lines in on step 2? Web.Config?

    ReplyDelete
  6. as specified already, I'm referring webpart user control (ascx).

    ReplyDelete
  7. I wrote webpart for SP2010.
    And I'm can't use Ajax Toolkit because I don't have access to master page (I can't remove the ScriptManager registration from the master page by removing the line).

    ReplyDelete
  8. Hi,

    Don't u have access to the sharepoint server? If you have access to the SharePoint server then u can open the site in sharepoint designer and modify the master page.

    ReplyDelete
  9. I too faced the same error while using Ajax with SP2010.I was struggling to resolve it at that time when searching in google i found your post and read it. What a great info you have given at the right time!! Thanks to Sohel to solve my error. Iam expecting more & more from you Sohel. Thanks a lot.

    http://godwinsblog.cdtech.in/2010/12/sharepoint-2010-root-of-certificate.html

    ReplyDelete
  10. During development webpart I certainly have access to the sharepoint server.
    But the webpart is distributed as an independent can be added by the user to any page.
    I have very little experience with sharepoint, maybe I am not very well understand you. If you can tell me a more detailed solution to this problem, then I'll be very grateful.

    ReplyDelete
  11. Very useful info. Hope MS will make changes to new version of Ajax Toolkit.

    ReplyDelete
  12. thank you for usefull information dude....u save my life...

    ReplyDelete
  13. I will be very thankful to u because of ur nice article
    Regards
    palani

    ReplyDelete
  14. Thanks all for your feedback. I'm glad that the post helps u.

    ReplyDelete
  15. Hi Sohel, It is a gr8 post. I followed your instruction, but i am getting " is not permittied" in the masterpage.

    Your help will be really appreciated.

    Thank you
    Jahangir

    ReplyDelete
  16. Is the new version (May 2011) compatible to SharePoint 2010?

    ReplyDelete
  17. Sohel,

    Thanks for the wonderful Post - I had downloaded the latest version of the Ajax Toolkit and for the life of me I could not figure out why it worked for non-SharePoint projects, but nothing for SharePoint projects in VS 2010. You have saved me a great deal of time.

    Thanks,

    Coltrane

    ReplyDelete
  18. hi sohel can i get free telerik dll for my project
    if yes plz give url

    thanx in advance.........

    ReplyDelete
  19. Hi Mukesh, Sorry Telerik dll is not free as I know and you need to buy the license from Telerik to use it.

    ReplyDelete
  20. Wow! It sure is a wonderful thing to learn that kind of application. It’s an added technique for a web developer to be able to make the best website.

    ReplyDelete
  21. Thank you very much for this exceptional post! It helped me to solve the problem with 'SYS undefined' Java Script error message.

    ReplyDelete
  22. I am facing issue, I have post it in forum..please kindly reply.

    http://social.msdn.microsoft.com/Forums/en-US/sharepoint2010general/thread/7af3c952-ec25-499f-8161-fcfb2b100bec

    ReplyDelete
  23. Thanks for good article, but... ;)
    add some note about session state(some controls will fail when is disabled)
    BR

    ReplyDelete
  24. check out the following post on ajax toolkit installation in sharepoint

    http://www.dotnetstadium.com/2012/06/ajax-toolkit-configuration-for.html

    ReplyDelete
  25. step 5 is not understood, actually if i opened the package file in Visual Studio means, it will not open as you mentioned in screen shot.
    It will open as a code window.
    how to open it as you said, pls help.
    -karthick

    ReplyDelete
  26. Hi Sohel..
    very useful post, I tried this in my development manchine.
    what if i want to add scriptmanager to master page on production server?

    Thanks
    Shiva

    ReplyDelete
  27. @Charan, you need to prepare a custom master page and deploy it with module. Then in the custom master page, you can add the script manager. Another way is to use delegate control.

    ReplyDelete
  28. Hi,
    I am using asp.net ajax(2.0 version) in sharepoint 2007 and visual studio 2005.It is not working.
    It shows error. i am followed this url( http://sharepoint.microsoft.com/blog/Pages/BlogPost.aspx?pID=806 )

    can any one help me please.......

    Thanks

    ReplyDelete
  29. Hi Sohel,
    I want to use Ajax tabcontrol in Sharepoint 2013. How shoudl I go about it?
    Thanks,

    ReplyDelete
  30. @Rekha, Instead of using Ajax Control Toolkit I would suggest to use jQuery Plugins which doesn't have server side dependency and less impact on deployment

    ReplyDelete
  31. Hi SOHEL, Thank good info. But i have problem yet.
    I want use Calendar Tool in SharePoint2013 webpart. So i made SharePoint Webpart, and wrote the ToolScriptmanager and CalendarEntender in ascx file. Project file has not error.
    But if i try arrangement webpart in sharepointsite. I got error `Can`t found file or assably AjaxControlToolkit Version=4.5.7.1005 Culture~~`.
    So I try this post, but I got error `Can`t found file or assably AjaxMin Version=4.5.7.1005 Culture~~`....changed error message AjaxControlToolkit -> AjaxMin.
    How are you think?Am i must use javascript?

    ReplyDelete
  32. Ajax Control toolkit should not be your choice. Please use jQuery calender or other plugins, they are more supported and popular now than Ajax Control Toolkit

    ReplyDelete
  33. This comment has been removed by the author.

    ReplyDelete
  34. thanks for great post
    ...but i have problem withe ajax script manager .when add it in the page it becomes too heavy ...if i replace it with default script manager the page load well but in this case ajax controls not work

    ReplyDelete
  35. Very Very Very Thanks
    Very Very Very Thanks
    Very Very Very Thanks

    please Ajax Control Toolkit with SharePoint 2013

    ReplyDelete

Note: Only a member of this blog may post a comment.