views:

3462

answers:

2

I have a a CollapsiblePanelExtender with the usual extend and collapse buttons....I would like to have a click event fire off when the extender is extended and a different click event fire off when the extender is collapsed. But the most important event is when it is extended. I could live without a click even on collapse.

Most of the examples I've found online searching using: "CollapsiblePanelExtender" "click event" is having the extender react based on a click even else where...

I want the extender to fire off a JS when clicked.

How should I go about accomplishing this? Am I asking the wrong question/using the wrong search strings?

   CollapsiblePanelExtender extendatron = new CollapsiblePanelExtender();
   extendatron.ID = "cpe" + MenuId;
   extendatron.TargetControlID = "pnlContent" + strMenuId;
   extendatron.ExpandControlID = "pnlMenu" + strMenuId;
   extendatron.CollapseControlID = "pnlMenu" + strMenuId;
   extendatron.Collapsed = bCollapsed;
   extendatron.TextLabelID = strMenuName;
   extendatron.ExpandedText = m_strButtonLabelHide;
   extendatron.CollapsedText = m_strButtonLabelShow;
   extendatron.ImageControlID = "imglnk" + strMenuId;
   extendatron.CollapsedImage = "~/App_Themes/default/nbExpand.gif";
   extendatron.ExpandedImage = "~/App_Themes/default/nbCollapse.gif";
   extendatron.SuppressPostBack = true;
   extendatron.ScrollContents = false;

   var extender = $find('extendatron'); //this would be <%=myExtender.ClientID%>
   extender.add_collapsed( function() { alert('collapsed'); });
   extender.add_expanded( function() { alert('expanded'); });
+1  A: 

I assume you're talking about the ASP.Net AJAX Control Toolkit. You can add handlers to the collapsed and expanded events as follows:

var extender = $find('myExtender_ClientId'); //this would be <%=myExtender.ClientID%>
extender.add_collapsed( function() { alert('collapsed'); });
extender.add_expanded( function() { alert('expanded'); });

Let me know if you have any questions...I've done a fair bit of customizing some of these objects in various solutions.

Jonas
Yes, I'm talking about the ASP.NET AJAX Control Toolkits collapsible panel extenderI'm trying to add it programmatically through the code behind using a non embedded script
aggitan
This code will still work for extenders added server-side. The extender creates a javascript object that you can get a reference to with the $find command.
Jonas
sorry, not sure if it was clear or not...the code I posted was meant to run in javascript, not c#. :)
Jonas
How would I go about adding/running it in C#?
aggitan
I don't believe that you can...those properties/hooks only exist client-side (javascript).
Jonas
A: 

How are you adding this into the javascript? I have extenders that I am creating dynamically in the code behind and I need to fire a javascript function on the expand and collapse.

Adam