事件不是从嵌套的 Accordion 控件中触发的

发布于 2024-11-18 21:18:08 字数 1860 浏览 2 评论 0原文

假设我们有 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 单击时执行,但不在 ButtonH2ButtonContent 上执行>点击。有人知道我想念什么吗?

谢谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

顾冷 2024-11-25 21:18:08

感谢 Tim Schmelter 我解决了这个问题。

这是他提到的论坛帖子,解释了需要进行的更改完成吧。我发现的摘要:

Accordion.cs 类需要从第 46 行的 INamingContainer 继承,

public class Accordion : WebControl, INamingContainer`

此相关 ASP.NET 帖子

和 Accordion ItemCommand 需要具有AccordionCommandEventArgs 在第 68 行的事件处理程序中定义:

public event EventHandler<AccordionCommandEventArgs> ItemCommand;
//public event CommandEventHandler ItemCommand;

此 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 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

時窥 2024-11-25 21:18:08

尝试设置 SuppressHeaderPostbacks="false"。这对我有用。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文