I created a new ASP.NET Web Forms project through Visual Studio 2012. Unfortunately, the Site.Master file is very confusing by default. (I am posting these questions together because they are very related and contain links to the same code.)
First, I already understand the purpose of linking and minimizing, so there is no need to discuss this. However, I do not understand what happens with the way scripts are included in the main page by default.
Question 1:
Why is the package "~ / bundles / WebFormsJs" created in the BundleConfig.cs file, and yet on the main page each of these individual .js files is displayed one after another in the ScriptManager?
Inside BundleConfig.cs:
bundles.Add(new ScriptBundle("~/bundles/WebFormsJs").Include( "~/Scripts/WebForms/WebForms.js", "~/Scripts/WebForms/WebUIValidation.js", "~/Scripts/WebForms/MenuStandards.js", "~/Scripts/WebForms/Focus.js", "~/Scripts/WebForms/GridView.js", "~/Scripts/WebForms/DetailsView.js", "~/Scripts/WebForms/TreeView.js", "~/Scripts/WebForms/WebParts.js"));
Inside Site.Master:
<body> <form runat="server"> <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>
As you can see ... each of the same .js files is separately specified in the ScriptManager. I donβt even see links to the "WebFormsJs" package that was created somewhere outside of BundleConfig.cs. Why has this package ever been created if each of these javascript files is mentioned separately here in ScriptManager?
Question 2:
Why is ScriptManager used this way at all? I was impressed that ScriptManager was necessary for Microsoft Ajax, for example, using UpdatePanels. What is the purpose of using ScriptManager here ... just to register javascript files?
Question 3:
What is the difference in registering javascript files with ScriptManager compared to the top of Site.Master, where the following approach is used instead?
<%: Scripts.Render("~/bundles/modernizr") %>
Question 4:
Inside ScriptManager, I also noticed:
<asp:ScriptReference Name="MsAjaxBundle" /> <asp:ScriptReference Name="jquery" /> <asp:ScriptReference Name="jquery.ui.combined" />
... I can at least recognize "MsAjaxBundle" from BundleConfig.cs, but where are jquery and jquery.ui.combined defined? I did a search and found a link to them in packages.config.
<package id="jQuery" version="1.7.1.1" targetFramework="net45" /> <package id="jQuery.UI.Combined" version="1.8.20.1" targetFramework="net45" />
But I do not understand what is happening here. I thought package.config was used for NuGet. Plus ... I donβt even see the path indicated here for the location of these jQuery.js files. They are listed here and are strangely related to a specific version of the .NET Framework (4.5 in my case). Why the javascript resource will be associated with a version of the .NET Framework outside of me.
In any case, question 4 is: how is the "jquery" resource added / used in the ScriptManager? Why can't I see jQuery.js files grouped together in BundleConfig.cs, like all other packages?
Question 5:
Can I remove the following script link from Site.Master if I do not plan to use UpdatePanel and those Microsoft Ajax controls? I'm a little confused why this is still included here by default.
<asp:ScriptReference Name="MsAjaxBundle" />