在 UpdatePanel 中找不到触发器的具有 ID 的控件
我有一个更新面板,其中 Conditional 的 UpdateMode 和 ChildrenAsTriggers 设置为 false。我只需要几个控件来引发异步回发:
<asp:UpdatePanel ID="updPnlMain" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false">
<ContentTemplate>
// ...
<asp:Repeater ID="rptListData" runat="server">
<ItemTemplate>
<asp:Button ID="btnAddSomething" runat="server" OnClick="btnAddSomething_Click" />
</ItemTemplate>
</asp:Repeater>
// ...
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnAddSomething" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
当我尝试加载此页面时,出现以下错误:
A control with ID 'btnAddSomething' could not be found for the trigger in UpdatePanel 'updPnlMain'.
由于我的 btnAddSomething 控件位于转发器中,并且可能不会立即出现,因此它的行为就像不存在一样。我该如何解决这个问题?
I have an update panel that has UpdateMode of Conditional and ChildrenAsTriggers set to false. I only want a few controls to cause an asynchronous postback:
<asp:UpdatePanel ID="updPnlMain" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false">
<ContentTemplate>
// ...
<asp:Repeater ID="rptListData" runat="server">
<ItemTemplate>
<asp:Button ID="btnAddSomething" runat="server" OnClick="btnAddSomething_Click" />
</ItemTemplate>
</asp:Repeater>
// ...
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnAddSomething" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
I am getting the following error when I try and load this page:
A control with ID 'btnAddSomething' could not be found for the trigger in UpdatePanel 'updPnlMain'.
Since my btnAddSomething control is in a repeater and might not be there right away it acts like it is nonexistent. How can I get around this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因为您的控件位于
repeater control
中,并且它超出了Trigger 集合
的范围。顺便说一下,您不需要添加触发器
,因为您的按钮控件已经在UpdatePanel
中,当您单击按钮时它将更新。编辑:如果您确实想更新 updPnlMain updatepanel,有一个解决方案。您可以放入另一个更新面板并将按钮放在该面板中。例如
,然后只需在
btnAddSomething_Click
事件中调用updPnlMain.Update();
方法即可。它实际上会做你正在寻找的:)
Because your control is in the
repeater control
and it is out of scope to theTrigger collection
. By the way you don't need toadd trigger
because your button control is already in theUpdatePanel
, it will update when you click the button.Edit: There is a solution if you really want to update your updPnlMain updatepanel. You can put in another updatepanel and put your button in that panel. e.g.
and then simply call the
updPnlMain.Update();
method inbtnAddSomething_Click
event.It will actually do what you are looking for :)