Combine scripts in asp.net ajax toolkit

We are using asp.net version 3.0.20229.0 ajaxControlTookKit (up to .net 3.5 sp1). I was wondering if I can combine our custom javascript files into ScriptResource.axd created by controlTookKit. I found this article ( http://blogs.msdn.com/delay/archive/2007/06/11/script-combining-made-easy-overview-of-the-ajax-control-toolkit-s-toolkitscriptmanager.aspx ) which tells me that I need to add the scriptCombine attribute to the assembly file. We are launching a WebSite project, how to add this attribute?

+6
ajax ajaxcontroltoolkit
source share
1 answer

You will need to add the scripts as resources to a separate library and reference them from there to use the script combiner.

Change to provide a walk through

Create a new class library project (for example, "CombinedScipts"), delete the default class.

Add a link to AjaxControlToolkit and System.Web

Add your JS files to the project and change their Build Action property to "Embedded Resource".

Open AssemblyInfo.cs

Add the following:

// You need to add a web resource call for each JS file in the project [assembly: WebResource("CombinedScripts.Console.js", "text/javascript")] [assembly: WebResource("CombinedScripts.Utilities.js", "text/javascript")] // Not setting IncludeScripts or ExcludeScripts marks all scripts as // combinable. [assembly: AjaxControlToolkit.ScriptCombine()] 

Add this library as a link to your website project.

In your project, you can add the following between ToolkitScriptManager tags:

 <Scripts> <asp:ScriptReference name="CombinedScripts.Console.js" assembly="CombinedScripts" /> <asp:ScriptReference name="CombinedScripts.Utilities.js" assembly="CombinedScripts" /> </Scripts> 

Remember that the CombineScripts ToolkitScriptManager property is set to true.

This results in a single call: /pageName.aspx?_TSM_HiddenField_=ToolkitScriptManager1_HiddenField& [...]

You will have merged scripts with comment delimiters like:

 //START CombinedScripts.Console.js [...] //END CombinedScripts.Console.js //START CombinedScripts.Utilities.js [...] //END CombinedScripts.Utilities.js 
+3
source share

All Articles