Chapter 4. The AJAX Runtime with the Microsoft AJAX Library

After completing this chapter, you will

  • Understand the ScriptManager server control and its role in deploying an AJAX application.

  • Understand object-oriented JavaScript and the Microsoft AJAX Library.

  • Understand and be able to utilize the Microsoft AJAX Library’s JavaScript type system.

In the first three chapters, we’ve looked at programming service-oriented AJAX applications using Windows Communication Foundation (WCF) to implement the back-end server. In this chapter we’ll start looking at client applications that use the ASP.NET AJAX client-side runtime, also known as the Microsoft AJAX Library, and the ASP.NET ScriptManager control.

Note

Note

The Microsoft AJAX Library refers to the client-side JavaScript framework of ASP.NET AJAX. ASP.NET AJAX includes both the client runtime as well as the server runtime.

Programming for the client runtime is a dramatic shift for most ASP.NET developers. We’re used to compiled code, drag-and-drop controls, and the Microsoft .NET Framework. We’re also used to object-oriented design patterns and principles, base classes, and inheritance. At first the JavaScript language can seem quite primitive to an ASP.NET developer. But with a little understanding of the JavaScript programming model and its rich support for inheritance and design patterns, you’ll be able to use JavaScript and the Microsoft AJAX Library to develop component-based application frameworks, utilizing the same modern object-oriented programming principles that you’re used to in managed code. Microsoft’s AJAX library is built specifically with .NET developers in mind and adds a type system on top of the loosely typed JavaScript language.

Understanding the Client-Side Programming Model

The client-side programming model is based on the Document Object Model (DOM), which is the browser’s interpretation of the HTML rendered on the Web page. Although the DOM programming model is similar in all Web browsers, it varies and is subtly different based on the underlying browser engine—for example, the Gecko engine is used by FireFox and Netscape browsers, the IE Engine is used by Internet Explorer, Webkit by Safari and Chrome, and Opera has its own engine as well. These variations make the DOM a problematic technology to deal with in applications that target all browsers, but the variations are limited in scope and generally deal with operations that are performed on XML or document nodes. The Microsoft AJAX Library’s DOM extensions handle cross-browser issues very well, so whenever you are working with the AJAX library you can be assured that your code works across browsers. In the following chapters, I’ll describe cross-browser framework classes, including Sys.UI.DomElement and Sys.UI.DomEvent, in more detail.

Tip

Tip

Whenever you program against the DOM directly, be aware of the subtle differences between DOM implementations and test with the versions of the browsers that you plan to support. It is common for modern applications to support Internet Explorer 7 and FireFox 2.0 at a minimum, although many organizations are still using Internet Explorer 6.

On top of the DOM sits JavaScript, which is relatively consistent across all modern browsers, although newer features of JavaScript 1.8 are not implemented in Internet Explorer. JavaScript 2.0 is also a work in progress and will be available in the releases of browsers after Internet Explorer 8 and Firefox 3.0; however, JavaScript 2.0 will have only minor changes and will retain the same loosely typed nature of JavaScript 1.2. Because JavaScript is the one language that is consistent across all Web browsers and is implemented in a robust and consistent manner in all Web platforms, it has become the language of the Web and will not be replaced any time soon.

The Microsoft AJAX Library itself is implemented with the JavaScript language and includes a type system, cross-browser support for DOM functionality, network libraries, a component model, and a control framework. Because the DOM and browser network libraries that use multiple implementations of XmlHttpRequest vary from browser to browser, the Microsoft AJAX Library’s cross-browser implementation and abstraction is one of its chief benefits.

Finally, on top of the Microsoft AJAX Library, an application developer can extend, build, and integrate AJAX frameworks and custom AJAX applications programmed to use Web services and other data sources. To put this all into an architecture diagram, Figure 4-1 depicts the client-side programming model of the Microsoft Ajax Library.

The AJAX application runtime is built on the DOM using JavaScript. It is implemented through the Microsoft AJAX Library, custom frameworks, and custom applications.

Figure 4-1. The AJAX application runtime is built on the DOM using JavaScript. It is implemented through the Microsoft AJAX Library, custom frameworks, and custom applications.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset