简体   繁体   中英

Dynamically Creating AJAX Accordian Controls

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM