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 acplishing 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'); });
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 acplishing 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'); });
Share
Improve this question
edited Aug 6, 2019 at 13:51
Brian Tompsett - 汤莱恩
5,89372 gold badges61 silver badges133 bronze badges
asked May 27, 2009 at 17:24
aggitanaggitan
2,3045 gold badges20 silver badges22 bronze badges
2 Answers
Reset to default 3I assume you're talking about the ASP.Net AJAX Control Toolkit. You can add handlers to the collapsed and expanded events as follows:
//this would be <%=myExtender.ClientID%> when using a master page
var extender = $find('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.
First, you need to create a client side (JavaScript) onClick
event for the panel or control users are clicking on.
So, go in there type onClick="functionName();"
<asp:Panel ID="pDocumentHeaderTitle" runat="server" CssClass="collapsePanelHeader" onClick="setCollapseState();">
<asp:Image ID="imgDocumentHeaderHeader" runat="server" ImageUrl="~/images/wadown.gif"/>Document Header
<asp:Label ID="lblDocumentHeaderHeader" runat="server">(Show)</asp:Label>
</asp:Panel>
Next: Add this javascript.
<script type="text/javascript">
function setCollapseState() {
var extenderDocumentHeader = document.getElementById("MainContent_cpeDocumentHeader_ClientState");
setCookie("cpeDocumentHeaderStatus", extenderDocumentHeader.value, 5)
}
//W3Schools cookie code.
function setCookie(c_name, value, exdays) {
var exdate = new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value = escape(value) + ((exdays == null) ? "" : "; expires=" + exdate.toUTCString());
document.cookie = c_name + "=" + c_value;
}
//W3Schools cookie code.
function getCookie(c_name) {
var i, x, y, ARRcookies = document.cookie.split(";");
for (i = 0; i < ARRcookies.length; i++) {
x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);
x = x.replace(/^\s+|\s+$/g, "");
if (x == c_name) {
return unescape(y);
}
}
}
</script>
Notice, when your page is loaded, there is a hidden field that is your collapsible panels state. It will be true or false. Go to page source and search for it you will find it.
Then add:
var extenderDocumentHeader = document.getElementById("MainContent_cpeDocumentHeader_ClientState");
So on click, get this clients state, save it in a cookie and your good to go!