最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c# - How to include latest Jquery using <asp:scriptreference> in asp.net 4.5? - Stack Overflow

programmeradmin4浏览0评论

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 /?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>

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./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>
Share Improve this question asked Mar 12, 2014 at 11:23 juhijuhi 3301 gold badge4 silver badges15 bronze badges 3
  • Not sure whether jquery bundle is automatically getting updated. Why dont you use Nuget jQuery package and manage with it? It is better to manually update the javascript libraries, whenever we want to upgrade – Murali Murugesan Commented Mar 12, 2014 at 11:33
  • Its not better to add updated version of jquery because some functions of methods are removed from previous versions and If you are using the same function in your code you have to take care of that yourself. like $.broswer was removed from newer version of jquery. rather than you can use cdn path of jquery version – Rajesh Kumar Commented Mar 12, 2014 at 11:37
  • i have to move to latest version as some plugins are not working properly. and as far as i know i have not use such function that can have conflict with jquery version. in short using latest Jquery is only option for me – juhi Commented Mar 12, 2014 at 11:40
Add a ment  | 

1 Answer 1

Reset to default 13

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./jquery.min.js",** 
        **CdnDebugPath = "http://code.jquery./jquery-latest.js"**, 
        CdnSupportsSecureConnection = true, 
        LoadSuccessExpression = "window.jQuery"
    }); 

and finally enable cdn in for the script manager

<asp:ScriptManager EnableCdn="True" />

might look little plicate but once you set it will work just fine.

发布评论

评论列表(0)

  1. 暂无评论