【问题标题】:<asp:updatePanel> inside a user control<asp:updatePanel> 在用户控件中
【发布时间】:2013-08-16 08:52:51
【问题描述】:

我在用户控件中使用 asp:UpdatePanel。 此用户控件包含在“.aspx”页面中。 注册和使用如下:

<%@ Register Src="~/Forms/TestPage.ascx" TagPrefix="ig" TagName="UserControl1" %>

    <asp:Panel ID="ucTestUserCntrl" Visible="false" runat="server">
       <ig:UserControl1 ID="UserControl1" runat="server" />
    </asp:Panel>

<!-- user control code in a diferent page '.ascx' file
-->
<%@ Control Language="C#" Debug="true" CodeFile="TestUserCntrl.ascx.cs"    Inherits="Test_WebUserControl"
AutoEventWireup="true" ClassName="TestUserControl" %>

<asp:Content ID="Content1" runat="server" ContentPlaceHolderID="MainContent">
    <asp:ScriptManager ID="ScriptManager1" EnablePartialRendering="true" runat="server">
    </asp:ScriptManager>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <asp:Timer ID="timer1" runat="server" Interval="1000" OnTick="Time_Tick">
            </asp:Timer>
            <asp:Label ID="lblTimeDisplay" Text="00:00:00" runat="server" />
        </ContentTemplate>
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="timer" EventName="Tick" />
        </Triggers>
    </asp:UpdatePanel>
</asp:Content>

用户控件如下所示:

有了这个我得到的错误是: “内容控件必须是内容页或引用母版页的嵌套母版页中的顶级控件。”

关于如何修复此错误的任何建议。

【问题讨论】:

  • 这不是经典的asp,它是asp.net

标签: asp.net updatepanel


【解决方案1】:

您必须将该用户控件放在&lt;ContentTemplate&gt;&lt;/ContentTemplate&gt; 中。如果您将它放在外面,那么它会像您一样给出错误。

<%@ Register Src="~/Forms/TestPage.ascx" TagPrefix="ig" TagName="UserControl1" %>



<!-- user control code in a diferent page '.ascx' file
-->
<%@ Control Language="C#" Debug="true" CodeFile="TestUserCntrl.ascx.cs"    Inherits="Test_WebUserControl"
AutoEventWireup="true" ClassName="TestUserControl" %>

<asp:Content ID="Content1" runat="server" ContentPlaceHolderID="MainContent">
    <asp:ScriptManager ID="ScriptManager1" EnablePartialRendering="true" runat="server">
    </asp:ScriptManager>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
<asp:Panel ID="ucTestUserCntrl" Visible="false" runat="server">
       <ig:UserControl1 ID="UserControl1" runat="server" />
    </asp:Panel>
            <asp:Timer ID="timer1" runat="server" Interval="1000" OnTick="Time_Tick">
            </asp:Timer>
            <asp:Label ID="lblTimeDisplay" Text="00:00:00" runat="server" />
        </ContentTemplate>
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="timer" EventName="Tick" />
        </Triggers>
    </asp:UpdatePanel>
</asp:Content>

【讨论】:

  • 内容模板,如果它在 .aspx 内而不是用户控件
猜你喜欢
  • 2018-01-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-02-19
  • 2020-01-07
  • 1970-01-01
  • 2013-05-28
  • 1970-01-01
相关资源
最近更新 更多