2

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.

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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!
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.