Friday, January 15, 2010

Combining AJAX Control Toolkit Resource Files

It is common to use quite a few AJAX Control Toolkit control on a single page. Each one creates a reference to a WebResource.axd or ScriptResource.axd files. Although they are small in size, the browser makes a separate request for each and every one of them. Given the limitations of only two concurrent connections/requests it results in a long load time.

The good news is there different solutions but essentially the result is the same.
1. Do it manually via IHttpModule and IHttpHandler
Read more

2. Use AJAX Control Toolkit

Just replace with in your ASPX page and that would do the trick. ToolkitScriptManager inherits from the ScriptManager therefore no errors will occur in the code behind.

A few properties that need to be included:
EnableScriptLocalization="true" EnablePageMethods="true" EnableScriptGlobalization="true" ScriptMode="Release" CombineScripts="true"

You might run into issue with turning on the CombineScripts="true". IE sometimes throws "Out of Memory" error message caused by infinite loop in the TextBoxWatermark Control JavaScript code:

AjaxControlToolkit.TextBoxWrapper.registerClass('AjaxControlToolkit.TextBoxWrapper', Sys.UI.Behavior);AjaxControlToolkit.TextBoxWrapper.validatorGetValue = function(id) { var control = $get(id);if (control && control.AjaxControlToolkitTextBoxWrapper) { return control.AjaxControlToolkitTextBoxWrapper.get_Value();} return AjaxControlToolkit.TextBoxWrapper._originalValidatorGetValue(id);}

The last line (which calls _originalValidatorGetValue) basically calls back this exact function over and over because control.AjaxControlToolkitTextBoxWrapper is undefined.

If you encounter the above error you should set the CombineScripts to "false".

No comments:

Post a Comment