[英]Repeater ItemCommand does not fire when clicking a button inside composite control
I have a Repeater
containing nested custom CompositeControl
controls in the following way: 我有一个Repeater
包含嵌套的自定义CompositeControl
控件,方法如下:
Wrapper
Head
Body
<asp:UpdatePanel ID="noteArea" UpdateMode="Conditional" ChildrenAsTriggers="false" runat="server" >
<ContentTemplate>
<asp:Repeater ID="noteRepeater" runat="server" EnableViewState="true" OnItemDataBound="noteRepeater_ItemDataBound" OnItemCommand="noteRepeater_ItemCommand">
<ItemTemplate>
<asp:Button runat="server" CommandName="edit" ID="testButton" />
<easit:NoteControl ID="noteControl" runat="server" />
</ItemTemplate>
</asp:Repeater>
</ContentTemplate>
</asp:UpdatePanel>
Head
control contains two Buttons
. Head
控包含两个Buttons
。 When I click on either of them, the ItemCommand
event of Repeater
doesn't get invoked. 当我单击其中任何一个时,不会调用Repeater
的ItemCommand
事件。 If I move the buttons right to ItemTemplate
, it works. 如果我将按钮向右移动到ItemTemplate
,它就可以工作。 But I need to keep them where they are. 但我需要把它们留在原地。
What is the correct way to bubble them up the control hierarchy? 将它们冒泡到控制层次结构的正确方法是什么?
You can have the control throw an event which your page (with the repeater) can listen for. 您可以让控件抛出您的页面(使用转发器)可以侦听的事件。 Any information you need for the event can be provided when initializing each control. 初始化每个控件时,可以提供事件所需的任何信息。
These controls are outside the ItemTemplate .. so they really can't trigger an ItemCommand. 这些控件在ItemTemplate之外..因此它们实际上无法触发ItemCommand。
An ItemCommand has specific attributes that will not be available to your buttons if they are outside the ItemTemplate (ItemIndex for instance, to determine the index of the clicked item) ItemCommand具有特定属性,如果它们位于ItemTemplate之外(例如ItemIndex,用于确定所单击项的索引),则按钮将无法使用这些属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.