通过 LoadControl() 加载的 UserControl 中的 UpdatePanel 不起作用?
我希望你能帮忙,因为我已经把头撞在墙上有一段时间了。 长话短说,我想使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于这些是动态控件,您必须将它们添加到回发页面,因此您需要删除“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.