Search code examples
c#asp.netrepeatercomposite-controls

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:

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. When I click on either of them, the ItemCommand event of Repeater doesn't get invoked. If I move the buttons right to ItemTemplate, it works. But I need to keep them where they are.

What is the correct way to bubble them up the control hierarchy?


Solution

  • 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.