Ajax Toolkit嵌套手风琴查找控件

时间:2015-09-28 21:22:59

标签: asp.net webforms accordion ajaxcontroltoolkit

我有一个嵌套的手风琴,我想在其中找到控制。

这是Html代码,

<div>
                <div>
                    <%--First Level--%>
                    <cc1:Accordion ID="accorFirst" runat="server" RequireOpenedPane="false" SelectedIndex="-1"
                        HeaderCssClass="header-first" HeaderSelectedCssClass="header_selected-first" ContentCssClass="content" ViewStateMode="Enabled" OnItemDataBound="AccordionFirstItemDataBound">
                        <HeaderTemplate>
                            <%#Eval("Name") %>
                        </HeaderTemplate>
                        <ContentTemplate>
                            <%--Second Level--%>
                            <asp:HiddenField ID="hdnIDFirst" runat="server" Value='<%#Eval("Id") %>' />
                            <cc1:Accordion ID="accorSecond" runat="server" RequireOpenedPane="false" SelectedIndex="-1"
                                HeaderCssClass="header-second" HeaderSelectedCssClass="header_selected-second" ContentCssClass="content" ViewStateMode="Enabled" OnItemDataBound="AccordionSecondItemDataBound">
                                <HeaderTemplate>
                                    <%#Eval("Name") %>
                                </HeaderTemplate>
                                <ContentTemplate>
                                    <asp:HiddenField ID="hdnIDSecond" runat="server" Value='<%#Eval("Id") %>' />
                                    <%--Third Level--%>
                                    <cc1:Accordion ID="accorThird" runat="server" RequireOpenedPane="false" SelectedIndex="-1" ViewStateMode="Enabled"
                                        HeaderCssClass="header-third" HeaderSelectedCssClass="header_selected-third" ContentCssClass="content">
                                        <HeaderTemplate>
                                            <%#Eval("Name") %>
                                        </HeaderTemplate>
                                        <ContentTemplate>
                                            <asp:TextBox ID="txtFirst" CssClass="test-class" runat="server"></asp:TextBox>
                                        </ContentTemplate>
                                    </cc1:Accordion>
                                </ContentTemplate>
                            </cc1:Accordion>
                        </ContentTemplate>
                    </cc1:Accordion>
                </div>
            </div>

我希望在按钮点击事件中获得每个“txtFirst”的值。请提供示例代码。提前致谢。

目前我正在使用此代码而未获得任何结果

 protected void btnSave_Click(object sender, EventArgs e)
{
    foreach (var first in accorFirst.Panes)
    {
        var accorSecond = first.FindControl("accorSecond") as Accordion;
        foreach (var second in accorSecond.Panes)
        {
            var accorThird = second.FindControl("accorThird") as Accordion;
            foreach (var third in accorThird.Panes)
            {
                var txtFirst = third.FindControl("txtFirst") as TextBox;
                string dataToSave = txtFirst.Text;
            }
        }
    }
}

1 个答案:

答案 0 :(得分:2)

您无法访问Accordion的ContentTemplate内的控件。不幸的是,这个控件并没有像UpdatePanel那样提供ContentTemplateContainer属性。

尝试将嵌套的Accordions置于Accordion Panes中,而不是将它们放在ContentTemplate中。