Asp.net 通过母版页上的脚本管理器使用脚本组合
ASP.NET 3.5 SP1为ScriptManager对象添加了一个很棒的新ScriptCombining功能,如上所示。但是,他只演示了如何在同一页面上与ScriptManager一起使用该功能。我希望在scriptmanager位于母版页上,但不知道如何以编程方式将每个页面所需的脚本添加到管理器的站点上使用此功能。我已经发现用它作为起点,但我并没有走得太远。谁能帮我一把吗 谢谢你,丹试一试:Asp.net 通过母版页上的脚本管理器使用脚本组合,asp.net,.net-3.5,asp.net-ajax,scriptmanager,Asp.net,.net 3.5,Asp.net Ajax,Scriptmanager,ASP.NET 3.5 SP1为ScriptManager对象添加了一个很棒的新ScriptCombining功能,如上所示。但是,他只演示了如何在同一页面上与ScriptManager一起使用该功能。我希望在scriptmanager位于母版页上,但不知道如何以编程方式将每个页面所需的脚本添加到管理器的站点上使用此功能。我已经发现用它作为起点,但我并没有走得太远。谁能帮我一把吗 谢谢你,丹试一试: ScriptReference SRef = new ScriptReference()
ScriptReference SRef = new ScriptReference();
SRef.Path = "~/Scripts/Script.js";
ScriptManager.GetCurrent(Page).CompositeScript.Scripts.Add(SRef);
这将获取当前的scriptmanager(即使它位于母版页上),并向CompositeScript属性添加脚本引用。您也可以在标记中使用 您可以将ScriptManager添加到母版页,例如
<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>
<asp:Content ID="HomeContent" ContentPlaceHolderID="PlaceHolder" runat="Server">
<asp:ScriptManagerProxy runat="server">
<CompositeScript>
<Scripts>
<asp:ScriptReference Path="~/yourscript.js" />
</Scripts>
</CompositeScript>
</asp:ScriptManagerProxy>
然后将ScriptManagerProxy添加到内容页,例如
<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>
<asp:Content ID="HomeContent" ContentPlaceHolderID="PlaceHolder" runat="Server">
<asp:ScriptManagerProxy runat="server">
<CompositeScript>
<Scripts>
<asp:ScriptReference Path="~/yourscript.js" />
</Scripts>
</CompositeScript>
</asp:ScriptManagerProxy>
谢谢。我明天进去的时候再试试