Thursday, August 8, 2013

AjaxControlToolkit with Visual Studio 2012

So, I tried today to create a new Web Site using the Visual Studio 2012 Template. I then proceeded into adding AjaxControlToolkit using the NuGet package.

Once I deployed (or debugged) the project, I kept getting the following script error:

        AjaxControlToolkit requires ASP.NET Ajax 4.0 scripts.

After scouring the internet for a cause, I came across this blog post from Tim, I successfully managed to use the Toolkit without any errors. The steps someone needs to follow are:
  1. Install the AjaxControlToolkit. I did this using the "Manage NuGet Packages" menu option, since it also easily resolves the package dependencies.
  2. Replace the <asp:ScriptManager> tag in the Site.Master page with <ajaxToolkit:ToolScriptManager>
  3. Remove the MsAjaxBundle ScriptReference tag.
  4. Remove the Assembly="System.Web" attribute from all the ScriptReference tags.
  5. Remove the Microsoft.AspNet.ScriptManager.MSAjax reference. This is not visible through the references, so you need to do this either using the "Manage NuGet Packages" menu option or using the NuGet Command Line interface, and entering Uninstall-Package Microsoft.AspNet.ScriptManager.MSAjax
That's it! Your project, including all the fancy AJAX controls you can add using the AjaxControlToolkit, will now work perfectly.

P.S. If the problem persists, you will need to go and manually delete the Microsoft.AspNet.ScriptManager.MSAjax.dll file from your output folder. After this, no problems should occur.