事件不是从嵌套的 Accordion 控件中触发的
假设我们有 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
上执行>点击。有人知道我想念什么吗?
谢谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
感谢 Tim Schmelter 我解决了这个问题。
这是他提到的论坛帖子,解释了需要进行的更改完成吧。我发现的摘要:
Accordion.cs 类需要从第 46 行的
INamingContainer
继承,如 此相关 ASP.NET 帖子
和 Accordion
ItemCommand
需要具有AccordionCommandEventArgs
在第 68 行的事件处理程序中定义:如 此 Codeplex 帖子
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 46as referred to in this related ASP.NET post
and the Accordion
ItemCommand
needs to have theAccordionCommandEventArgs
defined in the event handler on line 68:as referred to in this codeplex post
尝试设置
SuppressHeaderPostbacks="false"
。这对我有用。Try setting the
SuppressHeaderPostbacks="false"
. It worked for me.