在asp.net Ajax工具包相结合的脚本 [英] combine scripts in asp.net ajax toolkit
问题描述
我们使用的是asp.net ajaxControlTookKit的3.0.20229.0版(.NET 3.5 SP1之前)。我在想,如果我可以结合我们自定义的JavaScript文件到的ScriptResource.axd的controlTookKit造成的。我发现这篇文章(<一href="http://blogs.msdn.com/delay/archive/2007/06/11/script-combining-made-easy-overview-of-the-ajax-control-toolkit-s-toolkitscriptmanager.aspx">http://blogs.msdn.com/delay/archive/2007/06/11/script-combining-made-easy-overview-of-the-ajax-control-toolkit-s-toolkitscriptmanager.aspx) 它告诉我,我需要的scriptCombine属性添加到装配文件。我们正在运行一个网站项目,我怎么可以添加这个属性?
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 ScriptResource.axd that the controlTookKit creates. I've 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 running a WebSite project, how can I add this attribute?
推荐答案
您需要的资源,从那里添加脚本到一个单独的图书馆和参考他们采取脚本组合的优势。
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.
修改,以提供通过步行
创建一个新的类库项目(称为例如CombinedScipts),删除默认类。
Create a new Class Library project (called for example "CombinedScipts"), remove the default class.
添加一个引用到两个 AjaxControlToolkit中和的System.Web
Add a reference to both the AjaxControlToolkit and System.Web
添加您的JS文件到项目中,并改变它们的生成操作属性设置为嵌入的资源。
Add your JS files to the project, and change their Build Action property to "Embedded Resource".
打开AssemblyInfo.cs文件
Open the AssemblyInfo.cs file
添加以下内容:
// 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.
在你的项目,你就可以添加以下的ToolkitScriptManager标记之间:
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>
不要忘记,以确保ToolkitScriptManager的CombineScripts属性设置为true。
Not forgetting to ensure that the CombineScripts property of the ToolkitScriptManager is set to true.
这则导致一个调用是这样的: /pageName.aspx?_TSM_HiddenField_=ToolkitScriptManager1_HiddenField& [...]
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
这篇关于在asp.net Ajax工具包相结合的脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!