Question

I've got an asp.net page with some CollapsiblePanelExtender which is collapsed by default and contains CheckBoxes.
My problem is that when I expand one and check a CheckBox an AutoPostBack event is firing and my CollapsiblePanelExtender is collapsed again.

Is there a way to let the CollapsiblePanelExtender expand when I click a CheckBox with just C# and asp.net? I don't want to use JavaScript here.

Here is the configuration of my control:

CollapsiblePanelExtender cpe = new CollapsiblePanelExtender();
cpe.ID = "cpe" + headerName;
cpe.TargetControlID = headerName + "Body";
cpe.CollapsedSize = 0;
cpe.Collapsed = true;
cpe.ExpandControlID = headerName + "Header";
cpe.CollapseControlID = headerName + "Header";
cpe.AutoCollapse = false;
cpe.AutoExpand = false;
cpe.ScrollContents = false;
cpe.ExpandDirection = CollapsiblePanelExpandDirection.Vertical;
cpe.SuppressPostBack = false; 
Was it helpful?

Solution

It collapses because the html is replaced with what comes from the server after the postback, therefore, the CollapsiblePanelExtender returns to the default state.

If you can use UpdatePanels, consider the following:

Put the CollapsiblePanelExtender inside an UpdatePanel. Set the UpdatePanel UpdateMode="Conditional" and ChildrenAsTriggers="false".

The client state of the html inside that updatepanel will be maintained after the Postback because the panel will not update.

If you ever need it to update, you could update it manually by calling updatePanel.Update().

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top