Using ScriptCombining via ScriptManager on the homepage

ASP.NET 3.5 SP1 adds a new ScriptCombining feature to the ScriptManager object, as shown in this video . However, it only demonstrates how to use this function with the ScriptManager on the same page. I would like to use this feature on a site where the scriptmanager is on the home page, but cannot figure out how to add the scripts I need for each page, programmatically for the manager. I found this post to use as a starting point, but I'm not getting very far. can anyone help me?

Thanks Dan

+1


source to share


2 answers


Take a picture:

    ScriptReference SRef = new ScriptReference();
    SRef.Path = "~/Scripts/Script.js";


    ScriptManager.GetCurrent(Page).CompositeScript.Scripts.Add(SRef);

      



This will force the current scriptmanager (even if it's on the master page) and add the script link to the CompositeScript properties.

+2


source


You can also do this in markup using ScriptManagerProxy .

You can add a ScriptManager to the master page for example.

<asp:ScriptManager ID="ScriptManager" runat="server">
    <CompositeScript>
    <Scripts>
        <asp:ScriptReference name="WebForms.js" assembly="System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
        <asp:ScriptReference name="MicrosoftAjax.js" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <asp:ScriptReference name="MicrosoftAjaxWebForms.js" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    </Scripts>
    </CompositeScript>
</asp:ScriptManager>

      



Then add the ScriptManagerProxy to the content page eg.

<asp:Content ID="HomeContent" ContentPlaceHolderID="PlaceHolder" runat="Server">
    <asp:ScriptManagerProxy runat="server">
        <CompositeScript>
        <Scripts>
            <asp:ScriptReference Path="~/yourscript.js" />
        </Scripts>
        </CompositeScript>
    </asp:ScriptManagerProxy>

      

+1


source







All Articles