ID为控制找不到在UpdatePanel的触发器 [英] A control with ID could not be found for the trigger in UpdatePanel
问题描述
我有一个更新面板具有条件设置为false ChildrenAsTriggers的的UpdateMode。我只想要一些控件导致异步回发:
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'.
由于我btnAddSomething控制是一个中继器,可能不会有马上它的作用就像是不存在的。我怎样才能解决这个?
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?
推荐答案
由于您控制在 Repeater控件
和超出范围触发器集合
。顺便说一句,你不需要添加触发器
,因为你的按钮控制已处于的UpdatePanel
,它将更新时单击该按钮。
Because your control is in repeater control
and is out of scope to Trigger collection
. By the way you don't need to add trigger
because your button control is already in UpdatePanel
, it will update when you click the button.
编辑:有解决方案,如果你真的想更新updPnlMain的UpdatePanel。你可以把anohter的UpdatePanel,并把你的按钮,在面板上。例如,
There is solution if you really want to update your updPnlMain updatepanel. You can put anohter updatepanel and put your button in that panel. e.g.
<asp:UpdatePanel ID="updButton" runat="server" UpdateMode="Conditional">
<asp:Button ID="btnAddSomething" runat="server" OnClick="btnAddSomething_Click" />
</ContentTemplate>
然后只需调用 updPnlMain.Update();在
方法 btnAddSomething_Click
事件
and then simply call the updPnlMain.Update();
method in btnAddSomething_Click
event.
这实际上将你在找什么目前:)
It will actually do what you are looking currently :)
这篇关于ID为控制找不到在UpdatePanel的触发器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!