Search code examples
c#asp.netwebforms

Nested Accordion Controls are reporting as Null on Page_Load


I have a dropdownlist in a nested accordion.

On the page load I would like to bind that drop down list with data provided. However, when the method tries to find the dropdownlist control, it cannot find it and treats it as a null entity. This breaks the page load.

Here is a sample of the code that I'm referring to:

        <Panes>
          <ajaxToolkit:AccordionPane ID="apPane1" runat="server" Visible="true">
             <Header>
                <span class="AccordionLink">Header1</span>
             </Header>
             <Content>
                 <table style="width: 75%">
                    <tr>
                       <td style="padding: 0px 0px 0px 15px">
                           <asp:Panel ID="pnllandingpanel" runat="server"> 
                              <ajaxToolkit:Accordion ID="AccordionChartConfig" runat="server" SelectedIndex="0" RequireOpenedPane="false" CssClass="accordian" HeaderCssClass="headerCssClass" FadeTransitions="true" TransitionDuration="500" AutoSize="None" ContentCssClass="contentCssClass" HeaderSelectedCssClass="headerSelectedCssClass">
                                  <Panes>
                                    <ajaxToolkit:AccordionPane ID="apPanelLevel2" runat="server">
                                          <Header>
                                               <span class="AccordionLink">Link2</span>
                                          </Header>
                                          <Content>
                                             <asp:DropDownList ID="ddlLoadValue" runat="server"></asp:DropDownList>
                                          </Content>
                                          </Header>
                                   </ajaxToolkit:AccordionPane>
                                 </Panes>
                          </td>
                       </tr>
                    </table>
              </Content>
        </ajaxToolkit:AccordionPane>
</Accordion>

My c# code behind is simply:

ddlLoadValue = BindDDLValue(ddlLoadValue);

The code behind works. I'm not worried about that.

If I don't need to load the dropdown list on page load, it works fine. This happens when I am doing a new entry. However, when I try to load a saved entry, I need the controls in that nested accordion to populate.

I tried making sure the accordion was enabled and selected index was the one with the dropdown list. I was expecting the program to find the control and populate the dropdown.


Solution

  • The solution was to manually navigate through the nest using FindControl.

        AjaxControlToolkit.AccordionPane optionspane = (AjaxControlToolkit.AccordionPane)Master.FindControl("MainContent").FindControl("apPanel").FindControl("AccordionChartConfig").FindControl("apPanelLevel2");
        DropDownList dXAxisFormat = (DropDownList)optionspane.FindControl("ddlLoadValue");
           
    

    I was able to render the page properly after doing this.