title: Performance issue with ASP.NET page with many (hundreds of) CollapsiblePanelExtenders
body: <p>I'm maintaining an ASP.NET site where users can log on to register some set of data (for statistical purposes). One user registers data for a set of units, and for each of these units a set of forms are to be filled out (with a handful of fields in each form, but that doesn't matter here). One scenario is that a user has 12 units, and in each of these units there is 25 forms to be filled, meaning a total of 300 forms.</p>
  
  <p>The ASP.NET page for registering these data is made the following way: each form is in a panel that can be collapsed using an AjaxControlToolkit CollapsiblePanelExtender, and all forms in a unit is inside another panel that also can be collapsed. The result is that you have a tree view-like structure with the units on the top, and under each unit you can expand a set of forms, and further each form can be expanded to fill data (the page is loaded with all panels collapsed by default).</p>
  
  <p>The page is generated completely dynamically (as forms can be added in a database), and for generating the CollapsiblePanelExtenders I have the following code:</p>
  
  <pre><code>private CollapsiblePanelExtender GenerateCollapsiblePanelExtender(string id, Panel headerPanel, Panel contentPanel)
  {
      CollapsiblePanelExtender collapsiblePanel = new CollapsiblePanelExtender();
  
      collapsiblePanel.ID = id + ID_COLLAPSIBLE_PANEL_POSTFIX;
      collapsiblePanel.TargetControlID = contentPanel.ID;
      collapsiblePanel.CollapseControlID = headerPanel.ID;
      collapsiblePanel.ExpandControlID = headerPanel.ID;
      collapsiblePanel.Collapsed = true;
      collapsiblePanel.BehaviorID = collapsiblePanel.ID + ID_BEHAVIOUR_POSTFIX;
  
      return collapsiblePanel;
  }
  </code></pre>
  
  <p>With one user having 12 units each with 25 forms, this means a total of 312 CollapsiblePanelExtenders. As I said, they are all set to be collapsed by default, but here's the problem:</p>
  
  <p>When the page loads, they all appear to be expanded, and then the browser "starts collapsing them". This however takes a <em>very</em> long time (in Firefox I even get a warning about an unresponsive script, IE and Chrome only takes forever but without the warning). When all the "collapsing" is complete it works smooth to open and close single panels, but users have complained about the extremely slow initial loading. </p>
  
  <p>So my question is simple: is there a way to optimize this so that the loading goes smoother? Is it for instance possible to only load the header panels in each CollapsiblePanelExtender initially, and then load the content panel asynchronously in some way?</p>
  
  <p>One final clarification:<br>
  I know I could simply change the design of the page to only include one unit and thus reducing size of the contents drastically, but I hope to avoid this (users prefer the way with everything in one page). It would also mean a rather large change to the logic of the page (yes, I know - it's a poor code base at that point)</p>