Mike Nichols - Son of Nun Technology

Accordion ASP.NET Ajax bug

Here's a cute little bug that killed a few hours today.
I placed an Ajax Control Toolkit Accordion Control onto my pretty complex page today and the control wouldn't render. The <div> for the control would render for the control but it's panes were not rendering.

Having other Ajaxed controls I thot perhaps I had some kind of conflict somewhere. So I stripped those down (these were working fine). Nope.
ViewState is turned off for my website so I thot maybe that was it. Nope.
I finally whittled the problem down to a call to '_view.DataBind()' that is done in the OnInit() event from my Presenter. When I commented that out, POOF! there's my accordion control.

So I went to the source code's Sample Web Site that is included with the Toolkit and put this on the Accordion.aspx sample page:
    <script runat="server">
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);  this.DataBind();
        }
    </script>

Sure enough, the accordion was gone from the sample. So I am off to dig into the databinding they override and fix it. I have opened an isse on CodePlex here .
So if you are getting issues with Toolkit controls that have child controls, check the databinding routine...

UPDATE
I fixed this by revising the OnDataBinding method of the Accordion.cs file:

        /// <summary>

        /// DataBind the Accordion to its panes

        /// </summary>

        /// <param name="e">EventArgs</param>

        protected override void OnDataBinding(EventArgs e)

        {

            base.OnDataBinding(e);

            if (DataSource != null) //Revised by Mike Nichols for preventing hiding of control when no datasource is present

            {

                // reset the control state

                ClearPanes();

                ClearChildViewState();

 

                // and then create the control hierarchy using the datasource

                CreateControlHierarchy(true);

                ChildControlsCreated = true;

            }

        }


MIKE