假设我们有Accordion控制,其中有几个按钮放在其他Accordion控件中。问题是这些按钮的事件不在服务器端处理。示例:
我有以下代码:
<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>
代码隐藏:
protected void Button1_OnClick(object sender, EventArgs e)
{
var button = (Button)sender;
}
Button1_OnClick
方法仅在ButtonH
点击时执行,但不在ButtonH2
或ButtonContent
次点击时执行。有没有人有我想念的想法?
谢谢!
答案 0 :(得分:5)
感谢Tim Schmelter,我解决了这个问题。
Here is the forum post he referred to解释了需要完成的更改。我发现的摘要:
Accordion.cs类需要继承第46行的INamingContainer
public class Accordion : WebControl, INamingContainer`
中所述
并且手风琴ItemCommand
需要在第68行的事件处理程序中定义AccordionCommandEventArgs
:
public event EventHandler<AccordionCommandEventArgs> ItemCommand;
//public event CommandEventHandler ItemCommand;
中所述
答案 1 :(得分:-1)
尝试设置SuppressHeaderPostbacks="false"
。它对我有用。