combine scripts in asp.net ajax toolkit

后端 未结 1 1646
自闭症患者
自闭症患者 2021-01-05 14:13

We are using version 3.0.20229.0 of the asp.net ajaxControlTookKit (before .net 3.5 sp1). I was wondering if I can combine our custom javascript files into the ScriptResour

相关标签:
1条回答
  • 2021-01-05 15:03

    You would need to add the scripts as resources to a seperate library and reference them from there to take advantage of the script combiner.

    Edit to provide an walk through

    Create a new Class Library project (called for example "CombinedScipts"), remove the default class.

    Add a reference to both the AjaxControlToolkit and System.Web

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

    Open the AssemblyInfo.cs file

    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 reference in your web site project.

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

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

    Not forgetting to ensure that the CombineScripts property of the ToolkitScriptManager is set to true.

    This then results in one call to something like: /pageName.aspx?_TSM_HiddenField_=ToolkitScriptManager1_HiddenField&[...]

    Which will have your combined scripts in, with comment delimiters like:

    //START CombinedScripts.Console.js
    [...]
    //END CombinedScripts.Console.js
    //START CombinedScripts.Utilities.js
    [...]
    //END CombinedScripts.Utilities.js
    
    0 讨论(0)
提交回复
热议问题