Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Events are not fired from nested Accordion control

Suppose we have Accordion control with several buttons placed in other Accordion control. Issue is in the fact that those button's events are not handled on server side. Example:

I have following code:

<form runat="server">
<ajax:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</ajax:ToolkitScriptManager>
<ajax:Accordion ID="Accordion1" runat="server" Enabled="True" Visible="true">
    <Panes>
        <ajax:AccordionPane ID="AccordionPane1" runat="server">
            <Header>
                header1 <asp:button id="ButtonH" runat="server" text="ButtonH" onclick="Button1_OnClick" />
            </Header>
            <Content>
                <ajax:Accordion ID="Accordion12" runat="server" Enabled="True">
                    <Panes>
                        <ajax:AccordionPane ID="AccordionPane12" runat="server">
                            <Header>
                                header2 
                                <asp:button id="ButtonH2" runat="server" text="ButtonH2" onclick="Button1_OnClick" />
                            </Header>
                            <Content>
                                <asp:button id="ButtonContent" runat="server" text="Content" onclick="Button1_OnClick" />
                                content1</Content>
                        </ajax:AccordionPane>
                    </Panes>
                </ajax:Accordion>
            </Content>
        </ajax:AccordionPane>
    </Panes>
</ajax:Accordion>
</form>

Codebehind:

 protected void Button1_OnClick(object sender, EventArgs e)
 {
    var button = (Button)sender;
 }

Button1_OnClick method is executed only on ButtonH click but not on ButtonH2 nor ButtonContentclicks. Does anybody have any ideas what I miss?

Thanks!

like image 757
Andy Avatar asked Oct 10 '22 14:10

Andy


1 Answers

Thanks to Tim Schmelter I fixed this issue.

Here is the forum post he referred to that explains the changes that need to be done. A summary of what I found:

The Accordion.cs class needs to inherit from INamingContainer on line 46

public class Accordion : WebControl, INamingContainer`

as referred to in this related ASP.NET post

and the Accordion ItemCommand needs to have the AccordionCommandEventArgs defined in the event handler on line 68:

public event EventHandler<AccordionCommandEventArgs> ItemCommand;
//public event CommandEventHandler ItemCommand;

as referred to in this codeplex post

like image 54
Andy Avatar answered Nov 09 '22 00:11

Andy