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 ButtonContent
clicks. Does anybody have any ideas what I miss?
Thanks!
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With