结合asp.net ajax工具包中的脚本 [英] combine scripts in asp.net ajax toolkit

查看:29
本文介绍了结合asp.net ajax工具包中的脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们使用的是 3.0.20229.0 版的 asp.net ajaxControlTookKit(在 .net 3.5 sp1 之前).我想知道是否可以将我们的自定义 javascript 文件合并到 controlTookKit 创建的 ScriptResource.axd 中.我找到了这篇文章(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.

添加对 AjaxControlToolkitSystem.Web

将您的 JS 文件添加到项目中,并将它们的 Build Action 属性更改为Embedded Resource".

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆