开发者

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

开发者 https://www.devze.com 2022-12-13 16:29 出处:网络
Using .NET 3.5. How do I programmtically expand/collapse the panes contained 开发者_StackOverflow社区within a AJAX accordion control?

Using .NET 3.5.

How do I programmtically expand/collapse the panes contained 开发者_StackOverflow社区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>


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)


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.


If you put the accordion control in an asp.net ajax update panel, you can collapse all panes easily via the codebehind setting the selected index to zero.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号