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.
The message is pretty clear, so I replaced ScriptManager with ToolkitScriptManager:
<AjaxToolkit:ToolkitScriptManager ID="smContent" EnablePageMethods="true" EnableScriptGlobalization="true" EnableScriptLocalization="true" runat="server">
</AjaxToolkit:ToolkitScriptManager>
After that change everything seemed to work just fine, until I decided to log in. It happens that this project is using Sys.Services.AuthenticationService for login and logout operations. Any attempt to login resulted in 'object doesn't support this property or method' message. So something must be wrong with JavaScript's emitted by manager. I made a quick comparison of scripts referenced by ScriptManager and ToolkitScriptManager. Here are the headers of interesting one:
// Name: MicrosoftAjax.js
// Assembly: System.Web.Extensions
// Version: 3.5.0.0
// FileVersion: 3.5.30729.196
// Name: MicrosoftAjax.js
// Assembly: AjaxControlToolkit
// Version: 3.5.40412.0
// FileVersion: 3.5.40412.2
The MicrosoftAjax.js referenced by ToolkitScriptManager has a lot less content than the one referenced by ScriptManager. Judging by the first error message, this script should be the one from ASP.NET AJAX 4.0 scripts. If that's the case, lets take a look at Microsoft AJAX CDN for ASP.NET AJAX 3.5 and ASP.NET AJAX 4.0. As you can see, in ASP.NET AJAX 4.0 Microsoft has split MicrosoftAjax.js in a lot of smaller files. The one we need is MicrosoftAjaxApplicationServices.js, let's download it and add to ToolkitScriptManager scripts:
<AjaxToolkit:ToolkitScriptManager ID="smContent" EnablePageMethods="true" EnableScriptGlobalization="true" EnableScriptLocalization="true" runat="server">
<Scripts>
<asp:ScriptReference Path="~/Scripts/MicrosoftAjaxApplicationServices.js" />
</Scripts>
</AjaxToolkit:ToolkitScriptManager>
Unfortunately this still doesn't work. The reason is that inline script, which sets default path for service, is executed before the script we have just added. We need to set the path for the service ourselves:
<script type="text/javascript">
Sys.Application.add_init(function() { Sys.Services.AuthenticationService.set_path('<%= ResolveClientUrl("~/Authentication_JSON_AppService.axd") %>'); });
</script>
Now it will work. I hope that this will be helpful for people who will encounter similar problem.
Email
3 comments:
Thanks for helping me get on the right track. You can save a step by referencing the script from the assembly using the name attribute instead of the path to the script. It will take advantage of script combining and fix the path error.
instead.
oops, code didn't post. should be
<asp:ScriptReference Name="MicrosoftAjaxApplicationServices.js"/>
kool ...it worked like i was wanted...thank u..for saving my time...
Post a Comment