views:

27

answers:

1

I have an Accordion control that is populated dynamically. I want to catch the event raised when a new pane is clicked on to open. I don't see the event at all in intelli-sense and when I code it by hand anyways I get errors.

Is there any way to catch this event?

The goal is to let a control in the masterpage that is holding the Accordion know when the Accordion has changed so it can update another control.

+1  A: 

To handle the client-side selectedIndexChanged event:

function pageLoad()
{
    $find("accordionBehaviorID").add_selectedIndexChanged(
        accordion_selectedIndexChanged);
}

function accordion_selectedIndexChanged(sender, args)
{
    var oldIndex = args.get_oldIndex();
    var newIndex = args.get_selectedIndex();

    // Do something.
}

As usual, you can define and register the handler at the same time using an anonymous function:

function pageLoad()
{
    $find("accordionBehaviorID").add_selectedIndexChanged(
        function(sender, args) {
            // Do something.
        });
}
Frédéric Hamidi
Thanks for the code samples! I don't have any experience with anonymous functions. Where should that code be placed?
Justin C
It's up to you. You can place it between `<script>` tags in your page markup, or in an external `.js` file, or as an embedded resource in your assembly using [RegisterClientScriptResource()](http://msdn.microsoft.com/en-us/library/system.web.ui.clientscriptmanager.registerclientscriptresource.aspx).
Frédéric Hamidi
thanks, I got it to work once I replaced "accordionBehaviorID" with a break into .NET code to get the ClientID. So I ended up with $find('<%= myAcc.ClientID %>' + '_AccordionExtender').add_selectedIndexChangedand the ID I set on my Accordion control was "myAcc"
Justin C