Home / AJAX

HOW TO Use the Script Loader with the ScriptManager

RSS
Modified on 2009/12/04 17:35 by Stephen Walther Categorized as Uncategorized
ASP.NET Web Forms provides a ScriptManager control that can be used to integrate Ajax functionality into ASP.NET applications. The control is often used with the UpdatePanel to allow partial-page updates as users integrate with a GridView or any other type of server control that normally causes a full postback. In cases where a ScriptManager is used in a page the default scripts loaded by the ScriptManager need to be overriden in order to take advantage of the ASP.NET Ajax Library features. An example of overriding the default scripts loaded by the ScriptManager is shown next:
<asp:ScriptManager ID="sm" runat="server">
    <Scripts>
        <asp:ScriptReference 
            Name="MicrosoftAjax.js" 
            Path="~/Scripts/MicrosoftAjax.js" />
        <asp:ScriptReference 
            Name="MicrosoftAjaxWebForms.js" 
            Path="~/Scripts/MicrosoftAjaxWebForms.js" />
        <asp:ScriptReference 
            Path="~/Scripts/MicrosoftAjaxTemplates.js" />
        <asp:ScriptReference 
            Path="~/Scripts/ClientControls/RegisterClientControls.js" />
    </Scripts>
</asp:ScriptManager>    

The first ScriptReference overrides the version of the ASP.NET Ajax Library used by the ScriptManager control. This is important in order to take advantage of core features in the library. The second ScriptReference is used to override the version of the MicrosoftAjaxWebForms.js script that is normally rendered by the ScriptManager. Overriding this script is necessary when using an UpdatePanel control in a page. The final two scripts are not required and can be loaded using the ScriptManager or the Microsoft Ajax Library's Script Loader.