Developer

Microsoft embraces open source with jQuery

Microsoft plans to integrate the JQuery library into both the ASP.NET Web Forms and ASP.NET Model View Controller frameworks. Tony Patton outlines how jQuery may work within an ASP.NET application.

Microsoft recently announced plans to adopt jQuery as part of its official development platform. The inclusion of jQuery provides more features to ASP.NET developers. Here's a closer look at the combination and how jQuery may work within an ASP.NET application.

JavaScript development via jQuery

The jQuery JavaScript library is an open source JavaScript library that simplifies many aspects of JavaScript development. It provides a powerful framework in a small package and enjoys a loyal following among AJAX developers. Among its many features is the ease at which it allows you to work with anything within a Web page including the DOM, event handling, animation, and all aspects of AJAX.

In contrast to other JavaScript libraries, jQuery has a very small footprint (15 KB). In addition, it is cross-browser compatible and has a large following with extensive usage on major Web sites — NBC and Netflix are two great examples.

JQuery's features are beyond the scope of this article. For more information, check out the jQuery Web site; the site sets it apart from other frameworks, as it provides excellent documentation and example code.

ASP.NET and jQuery

Microsoft plans to integrate the JQuery library into both the ASP.NET Web Forms and ASP.NET Model View Controller (MVC) frameworks. The delivery model is the Microsoft AJAX Framework, which is a combination of ASP.NET AJAX and jQuery. The best features of both will be utilized to provide a framework for building powerful AJAX applications.

ASP.NET AJAX provides excellent features for working with AJAX requests, while providing plenty of components and controls (along with the AJAX Control Toolkit) for building AJAX enabled interfaces.

On the jQuery side, the features of selectors, animations, and plugins are utilized. Selectors allow you to easily grab elements from a DOM and manipulate them. The animation features of jQuery are excellent and easy to use. The plugin architecture is very powerful and has a loyal following, with many freely available plugins that expand the jQuery library.

With the adoption of jQuery, it will be fully integrated into future versions of Microsoft's flagship development environment Visual Studio. The integration will include IntelliSense support, making it much easier to utilize the jQuery library. jQuery will make its first appearance in ASP.NET MVC.

It is important to note that Microsoft has no plans to take over or build its own version of jQuery. The company will utilize the jQuery library as-is under its MIT license. However, Microsoft does plan on actively contributing to jQuery, so who knows how future jQuery development may be influenced.

In action

As I write this article, the inclusion of jQuery within ASP.NET is not available in any form, but you can easily download the library from the jQuery site and put it to use. Once downloaded, the jQuery source file is installed on the Web server and may be referenced with the following line:

<script src="jquery.js" mce_src="jquery.js" type="text/javascript"></script>

When working with ASP.NET with AJAX support, you can use the ScriptManager control to bring the jQuery library into the page, as the following snippet illustrates:

<asp:ScriptManager id="sm" runat="Server"><Scripts>

<asp:ScriptReference Path="jquery.js" />

</Scripts>

</asp:ScriptManager>

Once included or referenced, it is available for use within that Web Form.

The following example was given during a recent presentation. The code sets the background color (via CSS) for all textboxes on the page. It uses a jQuery selector to grab all textboxes with the CSS property used to manipulate the background color.

<script type="text/javascript">function pageLoad()

{

$(":text").css("background-color", "red");

}

</script>

More to come

While this article covers Microsoft's announcement regarding jQuery, the actual delivery of the technology remains to be seen with future versions of Microsoft products. On the Visual Web Developer Team Blog, Jeff King promises an updated IntelliSense file for Visual Studio 2008.

You can get up and running with jQuery in Visual Studio 2008 via the Visual Studio jQuery download. Channel 9 has a great tutorial about jQuery and ASP.NET. But the best way to get acquainted with jQuery is to dive into it using your ASP.NET applications.

An interesting combination

I know many developers who have been using jQuery within their ASP.NET applications for a long time. They are excited to have jQuery fully supported within the ASP.NET platform.

I find it interesting that Microsoft chose to go with jQuery as opposed to building its own solution. The power of open source software is validated by an industry behemoth. Of course, Microsoft will still push its CodePlex site for its own version of open source when and where they can, but it makes me wonder what other open source tools and libraries Microsoft may adopt in the future.

Do you currently utilize jQuery or another JavaScript library? Do you use them in ASP.NET applications? Share your experience with the Web Developer community by posting to the discussion.

Get weekly development tips in your inbox Keep your developer skills sharp by signing up for TechRepublic's free Web Developer newsletter, delivered each Tuesday. Automatically subscribe today!

About

Tony Patton has worn many hats over his 15+ years in the IT industry while witnessing many technologies come and go. He currently focuses on .NET and Web Development while trying to grasp the many facets of supporting such technologies in a productio...

Editor's Picks