Search code examples
asp.netajaxcontroltoolkitaccordion

ASP .NET C# - Programmatically expand/collapse AJAX accordion panes?


Using .NET 3.5.

How do I programmtically expand/collapse the panes contained within a AJAX accordion control?

My page will have several accordions controls which I want to be able to mass expand/collapse with some buttons.

UPDATE1

My final code solution looks like this:

<script language="javascript">
function collapse_all(flag)
{
if(flag==true)
{            
var behavior = $get("<%=Accordion1.ClientID%>").AccordionBehavior;            
behavior.set_SelectedIndex(-1);            
}
else
{
var behavior = $get("<%=Accordion1.ClientID%>").AccordionBehavior;            
behavior.set_SelectedIndex(0);            
}
}    
</script>

Solution

  • you can find the accourdion control in javascript and call "set_SelectedIndex(-1)"

    so (using jquery)

    $("#<%=Accordion1.ClientID%>_AccordionExtender").set_SelectedIndex(-1)
    

    if you have a few, you can either do them all discretly or use one of the jquery selectors to find them all, the accordions will have to have been set up to allow all panes to close i believe (RequireOpenedPane = false)