开发者

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!


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


Try setting the SuppressHeaderPostbacks="false". It worked for me.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜