如何包括最新的Jquery使用&LT; ASP:的ScriptReference&GT;在asp.net 4.5? [英] How to include latest Jquery using <asp:scriptreference> in asp.net 4.5?
问题描述
我想包括在我的web应用程序的最新的jQuery。
Bydefault的jQuery 1.7.1越来越负载。
我知道下面code是负责的。但我应该做加载jQuery的1.10?
&LT; ASP:的ScriptManager =服务器&GT;
&LT;脚本和GT;
&LT;% - 要了解更多关于捆绑在ScriptManager的脚本看到http://go.microsoft.com/fwlink/?LinkID=301884 - %GT;
&LT;% - 框架脚本 - %GT;
&LT; ASP:的ScriptReference NAME =MsAjaxBundle/&GT;
&LT; ASP:的ScriptReference NAME =jQuery的/&GT;
&LT; ASP:的ScriptReference名称=引导/&GT;
&LT; ASP:的ScriptReference名称=响应/&GT;
&LT; ASP:的ScriptReference NAME =WebForms.js大会=System.Web程序PATH =〜/脚本/的WebForms / WebForms.js/&GT;
&LT; ASP:的ScriptReference NAME =WebUIValidation.js大会=System.Web程序PATH =〜/脚本/的WebForms / WebUIValidation.js/&GT;
&LT; ASP:的ScriptReference NAME =MenuStandards.js大会=System.Web程序PATH =〜/脚本/的WebForms / MenuStandards.js/&GT;
&LT; ASP:的ScriptReference NAME =GridView.js大会=System.Web程序PATH =〜/脚本/的WebForms / GridView.js/&GT;
&LT; ASP:的ScriptReference NAME =DetailsView.js大会=System.Web程序PATH =〜/脚本/的WebForms / DetailsView.js/&GT;
&LT; ASP:的ScriptReference NAME =TreeView.js大会=System.Web程序PATH =〜/脚本/的WebForms / TreeView.js/&GT;
&LT; ASP:的ScriptReference NAME =WebParts.js大会=System.Web程序PATH =〜/脚本/的WebForms / WebParts.js/&GT;
&LT; ASP:的ScriptReference NAME =Focus.js大会=System.Web程序PATH =〜/脚本/的WebForms / Focus.js/&GT;
&LT; ASP:的ScriptReference NAME =WebFormsBundle/&GT;
&LT;% - 站点脚本 - %GT;
&LT; /脚本&GT;
&LT; / ASP:ScriptManager的&GT;
要做到这一点,你必须创建自己的JS捆绑它通常是在Global.asax中或App_Start / BundleConfig.cs
在那里你必须添加类似下面这样根据版本不断变化,从而可能会有所不同。
ScriptManager.ScriptResourceMapping.AddDefinition(jQuery的新ScriptResourceDefinition
{
PATH =〜/脚本/ jquery-+ STR +.min.js,//你的路径将被忽略
DebugPath =〜/脚本/ jquery-+ STR +的.js,//你的路径将被忽略
** CdnPath =HTTP://$c$c.jquery.com/jquery.min.js**
** CdnDebugPath =HTTP://$c$c.jquery.com/jquery-latest.js**,
CdnSupportsSecureConnection = TRUE,
LoadSuccessEx pression =window.jQuery
});
终于使CDN在脚本经理
&LT; ASP:ScriptManager的EnableCdn =真/&GT;
可能看起来有点复杂,但一旦你设置它会工作得很好。
i want to include latest jquery in my web application.
Bydefault jquery 1.7.1 is getting load.
i know following code is responsible for that. but what should i do to load jquery 1.10?
<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>
To do that you have to create your own JS bundle it is usually in Global.asax or App_Start/BundleConfig.cs
in there you have to add something like below this keep changes according to version so might be little different.
ScriptManager.ScriptResourceMapping.AddDefinition("jquery", new ScriptResourceDefinition
{
Path = "~/Scripts/jquery-" + str + ".min.js", //your path will be ignored
DebugPath = "~/Scripts/jquery-" + str + ".js", //your path will be ignored
**CdnPath = "http://code.jquery.com/jquery.min.js",**
**CdnDebugPath = "http://code.jquery.com/jquery-latest.js"**,
CdnSupportsSecureConnection = true,
LoadSuccessExpression = "window.jQuery"
});
and finally enable cdn in for the script manager
<asp:ScriptManager EnableCdn="True" />
might look little complicate but once you set it will work just fine.
这篇关于如何包括最新的Jquery使用&LT; ASP:的ScriptReference&GT;在asp.net 4.5?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!