Ajax脚本管理器和母版页

9 master-pages asp.net-ajax

我正在构建一个新网站,并希望使用Ajax控件.

我是否需要在MasterPage和每个内容页面上放置ScriptManager控件?或者只是在MasterPage上?(或者只是在内容页面上?)

Bul*_*nes 13

内容页面或MasterPages只能有一个ScriptManager控件.如果您的MasterPage上有ScriptManager控件,则可以将ScriptManagerProxy控件拖放到内容页面上,以使用任何给定的特定ASP.NET AJAX功能,例如:

<asp:Content ID="Content1" ContentPlaceHolderID="BodyContent" runat="server">
    <asp:ScriptManagerProxy ID="ScriptManagerProxy1" runat="server">
        <Services>
            <asp:ServiceReference Path="~/MyWebServices/YourCoolWebService.asmx" />
        </Services>
    </asp:ScriptManagerProxy>

    <%-- more content stuff goes here --%>
<asp:Content>
Run Code Online (Sandbox Code Playgroud)


ach*_*a99 6

您只能拥有一个ScriptManager.你也可以拥有它.将它放在母版页上可以节省在内容页面上添加它的任务.但是,只有在内容页面中包含自定义脚本,才能在脚本管理器中编写自定义脚本.如下所述,有两个ScriptManagers在加载页面时抛出错误.