假设我们有Accordion控制,其中有几个按钮放在其他Accordion控件中.问题是这些按钮的事件不在服务器端处理.例:
@H_403_2@我有以下代码:
<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>@H_403_2@代码隐藏:
protected void Button1_OnClick(object sender,EventArgs e) { var button = (Button)sender; }@H_403_2@Button1_OnClick方法仅在ButtonH单击时执行,但不在ButtonH2和ButtonContentclicks上执行.有没有人有我想念的想法? @H_403_2@谢谢!
解决方法
感谢Tim Schmelter,我解决了这个问题.
@H_403_2@Here is the forum post he referred to解释了需要完成的更改.我发现的摘要:
@H_403_2@Accordion.cs类需要从第46行的INamingContainer继承
public class Accordion : WebControl,INamingContainer`@H_403_2@如this related ASP.NET post所述 @H_403_2@并且Accordion ItemCommand需要在第68行的事件处理程序中定义AccordionCommandEventArgs:
public event EventHandler<AccordionCommandEventArgs> ItemCommand; //public event CommandEventHandler ItemCommand;@H_403_2@如this codeplex post所述