通过 LoadControl() 加载的 UserControl 中的 UpdatePanel 不起作用?

发布于 2024-09-08 14:26:18 字数 1386 浏览 3 评论 0原文

我希望你能帮忙,因为我已经把头撞在墙上有一段时间了。 长话短说,我想使用 LoadControl 动态加载 UserControls,其中包含自己的更新面板,并且当它们位于页面上时,能够通过其子项单独触发更新。

为了更好地解释,请参阅我的问题的极其简化的示例:

Default.aspx

<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div>
    <asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
</div>
</form>

Default.aspx.vb

 IF Me.IsPostBack = False
 Dim control As Control = LoadControl("WebUserControl.ascx")
 PlaceHolder1.Controls.Add(control)
 Dim control2 As Control = LoadControl("WebUserControl.ascx")
 PlaceHolder1.Controls.Add(control2)
 Dim control3 As Control = LoadControl("WebUserControl.ascx")
 PlaceHolder1.Controls.Add(control3)
 End If

WebUserControl.ascx

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true">
<ContentTemplate>
    <%= Now.ToLongTimeString%>
    <asp:Button ID="Button1" runat="server" Text="Button" />
</ContentTemplate>

如果您运行此命令,我希望加载每个控件,将其添加到占位符,然后当您单击该控件中的按钮时,只有该控件触发更新。

相反,它似乎不起作用。

如果我使用常用​​标签将控件添加到页面,它们可以正常工作,因此问题出在 loadControl/placeholder 问题中。

请帮忙!

I hope you can help as i've been banging my head against the wall for a while.
Long story short, I want to dynamically load UserControls with LoadControl which contain their own updatepanels, and when they're on the page, be able to trigger their updates individually via their children.

To explain better, see my extremely simplified example of my issue:

Default.aspx

<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div>
    <asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
</div>
</form>

Default.aspx.vb

 IF Me.IsPostBack = False
 Dim control As Control = LoadControl("WebUserControl.ascx")
 PlaceHolder1.Controls.Add(control)
 Dim control2 As Control = LoadControl("WebUserControl.ascx")
 PlaceHolder1.Controls.Add(control2)
 Dim control3 As Control = LoadControl("WebUserControl.ascx")
 PlaceHolder1.Controls.Add(control3)
 End If

WebUserControl.ascx

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true">
<ContentTemplate>
    <%= Now.ToLongTimeString%>
    <asp:Button ID="Button1" runat="server" Text="Button" />
</ContentTemplate>

If you ran this, i would like each control to be loaded, added to the placeholder, and then when you click the button in that control, only that control trigger an update.

Instead it doesn't seem to work.

If i add the controls to the page by using the usual tags, they work fine, so the issue is somewhere in the loadControl/placeholder issue.

PLEASE HELP!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

大姐,你呐 2024-09-15 14:26:18

由于这些是动态控件,您必须将它们添加到回发页面,因此您需要删除“IF Me.IsPostBack = False”“end if”。否则控件将在回发后从页面中消失。

As these are dynamic controls you have to add them to the page on postbacks so you need to remove 'IF Me.IsPostBack = False' 'end if'. otherwise the controls will disappear from the page after a postback.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文