【发布时间】:2014-01-16 07:23:31
【问题描述】:
我创建了一个新的 ASP.NET 4.5.1 Web 表单项目。
母版页中有一个脚本管理器 - 它列出了大量脚本,包括对 jquery 和 bootstrap 的引用:
<asp:ScriptManager runat="server">
<Scripts>
<%--To learn more about bundling scripts in ScriptManager see http://go.microsoft.com/fwlink/?LinkID=301884 --%>
<%--Framework Scripts--%>
<asp:ScriptReference Name="MsAjaxBundle" />
<asp:ScriptReference Name="jquery" />
<asp:ScriptReference Name="bootstrap" />
<asp:ScriptReference Name="respond" />
<asp:ScriptReference Name="WebForms.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebForms.js" />
<asp:ScriptReference Name="WebUIValidation.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebUIValidation.js" />
<asp:ScriptReference Name="MenuStandards.js" Assembly="System.Web" Path="~/Scripts/WebForms/MenuStandards.js" />
<asp:ScriptReference Name="GridView.js" Assembly="System.Web" Path="~/Scripts/WebForms/GridView.js" />
<asp:ScriptReference Name="DetailsView.js" Assembly="System.Web" Path="~/Scripts/WebForms/DetailsView.js" />
<asp:ScriptReference Name="TreeView.js" Assembly="System.Web" Path="~/Scripts/WebForms/TreeView.js" />
<asp:ScriptReference Name="WebParts.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebParts.js" />
<asp:ScriptReference Name="Focus.js" Assembly="System.Web" Path="~/Scripts/WebForms/Focus.js" />
<asp:ScriptReference Name="WebFormsBundle" />
<%--Site Scripts--%>
</Scripts>
</asp:ScriptManager>
这些脚本随后会包含在页面中。
我一直认为脚本管理器只是用于 AJAX 相关的脚本,但现在它似乎包含了所有的 js 脚本。它似乎也与捆绑和缩小冲突 - 因为它包含脚本而不是捆绑引用。
我在 Google 上搜索过,但无法找到实际上与 AJAX 无关的脚本管理器。
更新
我找到了对脚本管理器的 scripts 属性的引用,尽管它没有解释在其中列出所有页面脚本的好处/原因: http://msdn.microsoft.com/en-us/library/system.web.ui.scriptmanager.scripts(v=vs.110).aspx
【问题讨论】:
-
ASP.NET WebForms 早于现代捆绑和 AJAX。 ScriptManager 最初用于确保在页面中呈现较旧的 WebForms 部件(例如 Calendar 控件和 WebParts)所需的脚本。请注意,一般来说,WebForms 与现代 Web 开发不兼容,因为它使用 ASP.NET MVC,它可以让您更好地控制生成的标记。
-
我以前使用过 MVC——尽管我只需要快速完成一些东西,而不需要 MVC 的所有复杂性。 Web 表单在这方面似乎比 MVC 好得多。
-
脚本管理器已在 asp.net 4.5 中更新 - 捆绑和缩小已添加到 Web 表单中。这些是最新的功能 - 不应该一起工作吗?
标签: asp.net webforms asp.net-4.5