我一直在查看4.5中Web Forms的一些新功能,而且我遇到了一个不显眼的验证路障.
Web Forms 4.5中的不显眼验证依赖于jQuery,当它启用时,将在页面主体中的服务器表单内部生成jQuery脚本引用.这听起来很棒,我喜欢这个概念.它在我看过的演示中效果很好,代码中的减少/清理是一件很美妙的事情.
但是,当我在预先存在的项目中启用它时,我遇到了问题.问题是我有无数的页面和应用程序利用jQuery进行客户端交互(jQuery UI是一个典型的例子),在这些页面中我有一个jQuery引用和附带的代码在页面的标题部分.当启用不显眼的验证时,结果是页面上的第二个jQuery引用,并且标题中的javascript中断.
有没有办法让我告诉脚本管理器jQuery已经加载到页面中,以便第二个引用不会被添加?或者,有没有办法告诉脚本管理器或Web窗体框架检查页面是否存在现有的jQuery引用?
我使用Visual Studio 2012和内置模板(在Add - > New Project下)创建一个全新的ASP.NET Web Forms Web应用程序项目.在默认情况下提供的Site.Master页面中,我看到了一些针对JQuery的标记,它包含在下面.
考虑到以下标记,ASP.NET如何确定包含JQuery所需的路径?
<asp:ScriptManager runat="server">
<Scripts>
<%--Framework Scripts--%>
<asp:ScriptReference Name="MsAjaxBundle" />
<asp:ScriptReference Name="jquery" />
<asp:ScriptReference Name="jquery.ui.combined" />
<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>
Run Code Online (Sandbox Code Playgroud)
我没有看到任何配置文件或代码将jquery解析为"〜/ Scripts/jquery-1.7.1.js".我看到一个packages.config文件,但它没有明确描述必须以某种方式计算的路径.
有谁知道如何在运行时解决JQuery的javascript文件的路径?
asp.net jquery webforms visual-studio-2012 bundling-and-minification