Wahlin on .NET
It's All About the Scripts
C:\Program Files\Microsoft ASP.NET \ASP.NET 2.0 AJAX Extensionsv1.0.61025\MicrosoftAjaxLibrary \System.Web.Extensions\1.0.61025.0
Debug and release versions of the scripts are available at this location. The debug scripts are nicely formatted for easy reading and debugging, and the whitespaces are stripped out of the release scripts to minimize their size.
The ScriptManager control loads the scripts from the ASP.NET AJAX library. These scripts are required to support other AJAX controls and tasks performed in an AJAX-enabled Web page. The ScriptManager control also performs several other tasks such as loading debugged versions of a script, loading custom scripts and creating Web service client-side proxies.
You can define a basic ScriptManager control in an ASP.NET AJAX Web page using the following syntax:
The ScriptManager control relies on the ScriptResourceHandler HttpHandler (see my previous column on ASP.NET AJAX configuration) to access the scripts embedded in the System.Web.Extensions.dll assembly. The AJAX features needed by controls in a Web page determine which scripts are dynamically loaded from the assembly. Listing 1 shows an example of standard script output that's added to a Web page after the ScriptManager control executes.
The ScriptManager control does more than load ASP.NET AJAX Framework scripts. You can use its Scripts property and associated ScriptReference control to load custom scripts as well. Listing 2 shows an example of how you can use the ScriptManager control to load a custom script named MyScript.js. Custom scripts are rendered during the ScriptManager's PreRender event and are immediately added after the first two script references in Listing 1.
It's important to note that custom scripts using the ScriptManager must notify the client-side ASP.NET AJAX Framework when they have finished loading. You can make sure this process occurs by adding this line of code at the bottom of your custom script file:
if (typeof(Sys) !== 'undefined')
In cases where you want to load custom scripts without using the ScriptManager control, you can use the standard HTML <script> tag. However, you'll want to ensure that your scripts are loaded at the appropriate time during your Web page's client-side life-cycle, especially if your scripts rely on functionality defined in ASP.NET AJAX library scripts.
The ScriptManager control loads core ASP.NET AJAX Framework scripts that add AJAX functionality into your Web pages. You must add the a ScriptManager control to a Web page anytime you want to use ASP.NET AJAX with new or existing ASP.NET Web pages. In future columns, I will provide additional details on how you can use the ScriptManager control to work with debug and release scripts, as well as generate client-side Web service proxies.
Dan Wahlin (Microsoft MVP for ASP.NET and XML Web Services) is the founder of The Wahlin Group which specializes in .NET and SharePoint onsite, online and video training and consulting solutions. Dan also founded the XML for ASP.NET Developers Web site, which focuses on using ASP.NET, XML, AJAX, Silverlight and Web Services in Microsoft's .NET platform. He's also on the INETA Speaker's Bureau and speaks at conferences and user groups around the world. Dan has written several books on .NET including "Professional Silverlight 2 for ASP.NET Developers," "Professional ASP.NET 3.5 AJAX, ASP.NET 2.0 MVP Hacks and Tips," and "XML for ASP.NET Developers." Read Dan's blog here.