jQuery Included with Web Forms and MVC
The Visual Studio templates for both Web Forms and MVC include the open-source jQuery library. When you create a new website or project, a Scripts folder containing the following 3 files is created:
- jQuery-1.4.1.js – The human-readable, unminified version of the jQuery library.
- jQuery-14.1.min.js – The minified version of the jQuery library.
- jQuery-1.4.1-vsdoc.js – The Intellisense documentation file for the jQuery library.
Include the unminified version of jQuery while developing an application. Include the minified version of jQuery for production applications.
For example, the following Web Forms page illustrates how you can use jQuery to change the background color of ASP.NET TextBox controls to yellow when they have focus.
Content Delivery Network Support
The Microsoft Ajax Content Delivery Network (CDN) enables you to easily add ASP.NET Ajax and jQuery scripts to your Web applications. For example, you can start using the jQuery library simply by adding a <script> tag to your page that points to Ajax.microsoft.com like this:
The Microsoft Ajax Content Delivery Network supports SSL (HTTPS) in case you need to serve a web page using the Secure Sockets Layer.
<asp:ScriptManager ID=”sm1″ EnableCdn=”true” runat=”server” />
ScriptManager Explicit Scripts
In the past, if you used the ASP.NET ScriptManger then you were required to load the entire monolithic ASP.NET Ajax Library. By taking advantage of the new ScriptManager.AjaxFrameworkMode property, you can control exactly which components of the ASP.NET Ajax Library are loaded and load only the components of the ASP.NET Ajax Library that you need.
The ScriptManager.AjaxFrameworkMode property can be set to the following values:
•Enabled — Specifies that the ScriptManager control automatically includes the MicrosoftAjax.js script file, which is a combined script file of every core framework script (legacy behavior).
•Disabled — Specifies that all Microsoft Ajax script features are disabled and that the ScriptManager control does not reference any scripts automatically.
•Explicit — Specifies that you will explicitly include script references to individual framework core script file that your page requires, and that you will include references to the dependencies that each script file requires.
For example, if you set the AjaxFrameworkMode property to the value Explicit then you can specify the particular ASP.NET Ajax component scripts that you need:
<asp:ScriptManager ID="sm1" AjaxFrameworkMode="Explicit" runat="server"> <Scripts> <asp:ScriptReference Name="MicrosoftAjaxCore.js" /> <asp:ScriptReference Name="MicrosoftAjaxComponentModel.js" /> <asp:ScriptReference Name="MicrosoftAjaxSerialization.js" /> <asp:ScriptReference Name="MicrosoftAjaxNetwork.js" /> </Scripts> </asp:ScriptManager>