views:

1109

answers:

1

Hey all,

I'm trying to create Accordian Controlls Dynammically on Page Load, code wise this is what I have so far:

 // Create dynamic acordian control

                    AjaxControlToolkit.Accordion info = new AjaxControlToolkit.Accordion();
                    AjaxControlToolkit.AccordionPane infoPane = new AjaxControlToolkit.AccordionPane();

                    info.ID = hostelId;
                    info.FadeTransitions = true;
                    info.FramesPerSecond = 10;
                    info.TransitionDuration = 500;

                    Literal headerContent = new Literal();
                    headerContent.ID = hostelId + "_Header";
                    headerContent.Text = hostelName + " More Info ";

                    Literal content = new Literal();
                    content.ID = hostelId + "_Content";
                    content.Text = hostelName + " BOOM ";

                    infoPane.HeaderContainer.Controls.Add(headerContent);
                    infoPane.ContentContainer.Controls.Add(content);

                    info.Panes.Add(infoPane);

                    cell3.Controls.Add(info);

When I run the page, the contente for the Accordian control displays, but its just text and not the actual accordian. Just wondering if someone can point me in the right direction.

A: 

I'm guessing you also need to add the Accordion to the ScriptManager on your page.

scriptManager.Controls.Add(info);

Also, have you tried adding the control in another event handler? It seeems that Init is the event on which you should dynamically be adding controls, at least according to this Microsoft Support page. (I can't remember where I've done it in my web applications, but Init would sound right.)

Hope that helps.

Noldorin
Thanks mate, worked perfectly. It's running fine in Page_Load, I also forgot to hook up my CSS but after that its running superb!
bExplosion
Glad that solved the problem... And yeah, I wasn't sure that the code *needed* to be in Page_Init, though it would probably work just as well.
Noldorin