Pages

Thursday, February 5, 2009

How Microsoft AJAX Client Library is Organized


Recently I ran into confusion about how Microsoft Ajax Client Library is organized. After having my head clear on it, I decided to share my understanding with you. In this post, we will see how the client library is organized across different JavaScript files and Namespaces.

First, the Microsoft Ajax Client Library is organized in JavaScript files. The following three JavaScript files make up the client library:

1. MicrosoftAjax.js
2. MicrosoftAjaxTimer.js
3. MicrosoftAjaxWebForms.js

These JavaScript files are embedded as resources in the Sytem.Web.Extensions assembly. This assembly is installed in the Global Assembly Cache (GAC) by the Microsoft Ajax Extension installer. As you know that every Microsoft ASP.NET Ajax application has one ScriptManager control. It’s this ScriptManager which is actually responsible for loading the JavaScript files in the asp.net page. So we must include the ScriptManager control to enable Ajax functionality in our applications.

Second, the JavaScript files (library) consist of many client classes which are then organized into client namespaces. These namespaces include:

1. Sys
2. Sys.Net
3. Sys.UI
4. Sys.Services
5. Sys.Serialization
6. Sys.WebForms

My confusion was about the difference between the JavaScript files and the Namespaces (client classes). Are these separate or do they complement each other. So here is what I understood after talking to the experts.

The JavaScript files (MicrosoftAjax, MicrosoftAjaxTimer, MicrosoftAjaxWebForms) represent the physical organization (features split in different files) whereas the Namespaces (Sys, Sys.Net, Sys.UI etc) correspond to the logical grouping (client classes into namespaces) of the client library. The namespaces span across the JavaScript files (and so do the client classes). When the JavaScript files are loaded in the web page, the entire client library (namespaces and client classes) gets loaded.

One point worth noting is that the JavaScript files come in two versions – the debug and release version. The ScriptManager always loads the release version (a stripped down version with no comments and debugging tricks) in the asp.net page unless specified. If we want to load a debug version of the script files, we can do so by using the following syntax:



<asp:ScriptManager ID=”ScriptManager1” runat=”server”>
<Scripts>
<asp:ScriptReference Path=”~/ScriptLibrary/ScriptFile” ScriptMode=”Debug”/>
</Scripts>
</ScriptManager>


Summary


In this post, we saw how Microsoft Ajax Client Library is organized. The JavaScript files represent the physical organization of the library. The namespaces represent the logical arrangement of client classes. The JavaScript files have many client classes and these classes are arranged under the different namespaces. The namespace (hence client classes) span across the JavaScript files.

I hope this post was useful in removing any doubts regarding the arrangement of the Ajax Client Library. Stay tuned for more…

No comments:

Post a Comment