主页面和内容页面中的ScriptManager

时间:2014-07-09 15:36:48

标签: c# asp.net

我对Scriptmanager有疑问,我的问题是: 我需要在母版页中使用ScriptManager:

<asp:ScriptManager ID="scriptManger1" runat="server">
    <Scripts>
        <asp:ScriptReference Name="MsAjaxBundle" />
        <asp:ScriptReference Name="jquery" />
        <asp:ScriptReference Name="bootstrap" />
        <asp:ScriptReference Name="respond" />
        <asp:ScriptReference Name="WebForms.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebForms.js" />
        <asp:ScriptReference Name="WebUIValidation.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebUIValidation.js" />
        <asp:ScriptReference Name="MenuStandards.js" Assembly="System.Web" Path="~/Scripts/WebForms/MenuStandards.js" />
        <asp:ScriptReference Name="GridView.js" Assembly="System.Web" Path="~/Scripts/WebForms/GridView.js" />
        <asp:ScriptReference Name="DetailsView.js" Assembly="System.Web" Path="~/Scripts/WebForms/DetailsView.js" />
        <asp:ScriptReference Name="TreeView.js" Assembly="System.Web" Path="~/Scripts/WebForms/TreeView.js" />
        <asp:ScriptReference Name="WebParts.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebParts.js" />
        <asp:ScriptReference Name="Focus.js" Assembly="System.Web" Path="~/Scripts/WebForms/Focus.js" />
        <asp:ScriptReference Name="WebFormsBundle" />
    </Scripts>
</asp:ScriptManager>

我需要在我的内容页面中使用ScriptManager,因为如果我在运行应用程序时从此处删除,则会出现错误,因为我需要一个ScriptManager,如果我在运行应用程序时放入ScripManager,则会出现错误,因为我有2 ScriptManager,因为我在母版页中有1个,在内容页面中有1个。

我的问题是我如何解决这个问题?

1 个答案:

答案 0 :(得分:11)

你是对的,你只能有一个ScriptManager。这绝对应该放在你的母版页中。要在其他页面中获取ScriptManager功能,您需要使用ScriptManagerProxy。可以将此代理视为将所有请求分叉到主页中加载的真实ScriptManager。

在你的其他页面中折腾这个小家伙:

 <asp:ScriptManagerProxy id="ScriptManagerProxy1" runat="server"/>

以下是有关如何更详细地应用此内容的详细说明:

http://www.dotnetheaven.com/article/ajax-package-scriptmanagerproxy-control-in-asp.net-using-vb.1