6

I used Visual Studio 2012 and the built-in template (under Add -> New Project) to create a brand new ASP.NET Web Forms web application project. Inside the Site.Master page provided by default I see some markup targeting JQuery, which is included down below.

How does ASP.NET figure out the paths necessary to include JQuery, given the following mark up?

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

I don't see anywhere a config file or code that would resolve jquery to "~/Scripts/jquery-1.7.1.js". I see a packages.config file but it doesn't explicitly describe the path that must be being calculated somehow.

Does anyone know how the path to JQuery's javascript file is resolved at runtime?

Jason Parker
  • 4,960
  • 4
  • 41
  • 52
  • dont you have a "scripts" folder in your solution somewhere? – Thousand Sep 17 '12 at 21:22
  • Have a look at your other question here: http://stackoverflow.com/questions/12290537/vs2012-web-forms-bundling-confusion the answer seems to offer some clarification I think. The answer seems to indicate that the packages place the jQuery files into the script folder which are then automatically added at runtime from there without requiring any further referencing. – Nope Sep 17 '12 at 21:42
  • Jane: yes I do have a scripts folder w/ all the JQuery javascript files in there... but my question is how the path to this directory is generated. – Jason Parker Sep 17 '12 at 21:52
  • François: Yeah... I was having quite a bit of difficulty understanding the answer provided there, so I figured I could at least break out this one question by itself and attempt to get some clarity. I am now aware that by default the Web Forms project (apparently) has NuGet packages for JQuery installed. I see them under References for the project. I think I saw somewhere that a Base JQuery UI theme pack is included as well.... so makes it a little difficult to upgrade to a custom downloaded JQuery UI themepack... I am not sure if I ought to remove the JQuery NuGet package... – Jason Parker Sep 17 '12 at 21:57

1 Answers1

4

Inside the Microsoft.ScriptManager.WebForms PreAppStartCode, it has:

        System.Web.UI.ScriptManager.ScriptResourceMapping.AddDefinition("WebFormsBundle", new ScriptResourceDefinition
        {
            Path = "~/bundles/WebFormsJs",
            CdnPath = "http://ajax.aspnetcdn.com/ajax/4.5/6/WebFormsBundle.js",
            LoadSuccessExpression="window.WebForm_PostBackOptions",
            CdnSupportsSecureConnection = true
        });

This is what hooks up to the declarations from the script reference:

<asp:ScriptReference Name="WebFormsBundle" />

And also does the deduplication because the ScriptReference path is the same as the path for the files inside of your bundle which should be registered inside of BundleConfig.cs

Hao Kung
  • 28,040
  • 6
  • 84
  • 93
  • 3
    For anyone wondering where this is, if you reflect `Microsoft.ScriptManager.WebForms.dll` its in the `Start()` method. – maxp Jul 29 '13 at 09:51
  • 1
    I still don't understand why you have the webformsbundle in BundleConfig.cs and in the ScriptManager. You say it is for "deduplication", but what does that mean? Deduplication of what? Why is it defined twice. This seems ludicrous. – Matt Jul 28 '15 at 15:28