The Microsoft AJAX Client-side library is now split up
across multiple JavaScript files – allowing you to download and use only those
script files that you actually need (reducing download sizes).
Manually adding all of the script files required to use Ajax
controls can be tedious though (and error prone). To make it easier to use both
client controls as well individual client library components, we are
introducing a new client script loader with today’s release. This client script
loader helps you automatically load all of the scripts required by a control
and execute the scripts in the right order when a page loads.
For example, the following page uses the client script
loader to load all of the scripts required by the “watermark” control, and then
wires up the watermark control to an <input> textbox:
Figure 7
Notice the call to the Sys.require() method above. When you
call Sys.require(), you supply the name of a client component (or an array of
client components) that you want to load. The sys.require() client loader then
automatically downloads all of the required script files in parallel (allowing
your scripts to load faster and also allow you to avoid blocking the page from
rendering). When all of the scripts required by the components requested
are loaded, the Sys.onReady() method is called and the watermark is created.
Above we are binding the “watermark” control to a
<input> textbox with an id of “name”. At runtime the watermark
control will cause the textbox to have a watermark (that automatically
disappears when a user sets the focus on the textbox and starts typing):
Figure 8
The client script loader supports many advanced features
including automatic script combining and lazy loading. It can also be smart
about downloading either debug or release versions of libraries. It also allows
you to register your own libraries and have them automatically be loaded as
well using the Sys.require() syntax.