concept ScriptManager in category .net

appears as: ScriptMager, The ScriptMager
ASP.NET AJAX in Action

This is an excerpt from Manning's book ASP.NET AJAX in Action.

The new set of server controls adds to the impressive arsenal of tools in the ASP.NET toolbox and is predominantly driven by two controls. The first of these controls is the ScriptManager, which is considered the brains of an Ajax-enabled page. One of the many responsibilities of the ScriptManager is orchestrating the regions on the page that are dynamically updated during asynchronous postbacks. The second control, named the UpdatePanel, is used to define the regions on the page that are designated for partial updates. These two controls work together to greatly enhance the user experience by replacing traditional postbacks with asynchronous postbacks. This results in regions of the page being updated incrementally rather than all at once with a full page refresh.

Setting the EnableScriptLocalization property of the ScriptManager to true forces the control to retrieve script files for the current culture, if they’re available. By default, this property is set to false, which means it doesn’t perform any localization lookup for you. Consequently, if you now include a script reference for SomeScript.js, intentionally omitting the culture name, the appropriate file is downloaded:

<asp:ScriptManager ID="ScriptManager1" runat="server"
   EnableScriptLocalization="true">
    <Scripts>
        <asp:ScriptReference Path="SomeScript.js" />
    </Scripts>
</asp:ScriptManager>

To reiterate, if the UI culture on your machine were set to Italian, then SomeScript.it-IT.js would be downloaded. Under the hood, the ScriptManager uses the naming convention you just exposed to look for a match against the current culture. You can also force a specific culture by setting the ResourceUICultures property in the ScriptReference:

The ScriptManager makes localization very easy and includes an additional set of features that make it an attractive solution for managing localization.

You should now have a general idea of what the ScriptManager is capable of. More instances of how and when it should be used are covered throughout the book as we mentioned. Let’s get back to the application and make use of another server control called the ScriptManagerProxy.

4.3.1. Understanding the ScriptManager

The primary responsibility of the ScriptManager is to deliver scripts to the browser. The scripts it deploys can originate from the ASP.NET AJAX library—embedded resources in the System.Web.Extensions.dll, local files on the server, or embedded resources in other assemblies. By default, adding the control to the page, declaratively or programmatically, delivers the required scripts you need for Ajax functionality on the page. To see the evidence, right-click the home page from the browser, and select the View Source option (or select View > Source in IE, or View > Page-Source in Firefox). In the viewed source window, search for an occurrence of ScriptResource.axd. You’ll find something similar to (but not exactly like) listing 4.1.

Listing 6.2. Adding the ScriptManager and UpdatePanel to replace the page refresh with a partial-page update