views:

823

answers:

2

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>
+1  A: 

You can't expand them programmatically via you server-side code(VB.NET/C#) because the expansion of the panes is done in the client-side code(JavaScript). If I were you I'd suggest taking a look at the JQuery Libraries and using their show/hide functions to build a custom accordion control to do what you want. JQuery will seem less "WebForm-like" but you'll find it much more flexible than the AJAX Control Toolkit.

Achilles
+1  A: 

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)

Pharabus
Thanks. I was really hoping that code-behind would work ...oh well.
John M
you can do it in code behind too, set the SelectedIndex of the control to -1, however this requires a server round trip on a click. Dont forget the controls RequireOpenedPane needs to be false to allow this.
Pharabus