How to include latest Jquery using <asp:scriptreference> in asp.net 4.5?
Asked Answered
D

1

6

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>
Dell answered 12/3, 2014 at 11:23 Comment(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 upgradeDhiren
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 versionLapel
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 meDell
T
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.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.

Tallowy answered 12/3, 2014 at 14:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.