However, I'm not really that experienced in the use of dynamic controls and am having some issues with getting the accordion to work properly.
What happens when one of my user controls fires a postback is that the accordion gets set back to the first pane. I suspect that this is happening because I'm repopulating the control. I have thought that maybe I could set an "ID" for each control as it is added, and then get every control to set its "ID" into the viewstate somewhere so that I could set the correct accordion pane to display, but this seems overly complicated.
Question:Can anyone here suggest a better way of doing this?
another question: I'm also interested to know if I actually have to retrieve the controls with the LoadControl() method each time. This seems a little cumbersom?
Here is the complete code for my "containing" control....
Expand|Select|Wrap|Line Numbers
- public partial class CrystalReportsParameterControls_ParameterPrompt : System.Web.UI.UserControl
- {
- ParameterFieldDefinitions m_ParameterFieldDefinitions;
- List m_PageControls;
- List m_AccordionPanes;
- #region Properties
- public ParameterFieldDefinitions ParameterFieldDefinitions
- {
- get
- { return m_ParameterFieldDefinitions; }
- set
- { m_ParameterFieldDefinitions = value; }
- }
- public List PageControls
- {
- get
- {
- if (m_PageControls == null)
- {
- m_PageControls = new List();
- }
- return m_PageControls;
- }
- set
- {
- if (m_PageControls == null)
- {
- m_PageControls = new List();
- }
- m_PageControls = value;
- }
- }
- public List AccordionPanes
- {
- get
- {
- if (m_AccordionPanes == null)
- {
- m_AccordionPanes = new List();
- }
- return m_AccordionPanes;
- }
- set
- {
- if (m_AccordionPanes == null)
- {
- m_AccordionPanes = new List();
- }
- m_AccordionPanes = value;
- }
- }
- #endregion
- protected void LoadUI()
- {
- Accordion l_Accordion = LoadAccordionControl();
- // Loop thru List of controls and add each to teh pane
- foreach (AccordionPane ap in AccordionPanes)
- {
- l_Accordion.Panes.Add(ap);
- //panelParameterPrompt.Controls.Add(uc);
- }
- panelParameterPrompt.Controls.Add(l_Accordion);
- }
- protected Accordion LoadAccordionControl()
- {
- Accordion l_Accordion = new Accordion();
- l_Accordion.ID = "m_accParameterControls";
- l_Accordion.SuppressHeaderPostbacks = true;
- l_Accordion.HeaderCssClass="accordionHeader";
- l_Accordion.ContentCssClass="accordionContent";
- l_Accordion.FadeTransitions=true;
- l_Accordion.FramesPerSecond=40;
- l_Accordion.TransitionDuration=250;
- l_Accordion.Width = 500;
- l_Accordion.AutoSize = AutoSize.None;
- l_Accordion.EnableViewState=true;
- return l_Accordion;
- }
- protected void Page_Init(object sender, EventArgs e)
- {
- BaseCrystalReportParameterControl pc;
- AccordionPane ap;
- Label lbl;
- foreach (ParameterFieldDefinition pfd in ParameterFieldDefinitions)
- {
- if (pfd.ParameterFieldUsage == ParameterFieldUsage.InUse)
- {
- pc = new BaseCrystalReportParameterControl();
- ap = new AccordionPane();
- lbl = new Label();
- if (pfd.ReportName.Length == 0) // Has no name if belongs to main report, else Sub report.
- {
- if (pfd.ParameterValueKind == ParameterValueKind.DateParameter)
- {
- pc = LoadDiscreteDate();
- pc.ParameterFieldDefinition = pfd;
- }
- if (pfd.ParameterValueKind == ParameterValueKind.StringParameter)
- {
- pc = LoadDiscreteValueStringWithDefaults();
- pc.ParameterFieldDefinition = pfd;
- }
- ap.ContentContainer.Controls.Add(pc);
- lbl.Text = pc.ParameterFieldDefinition.PromptText;
- ap.HeaderContainer.Controls.Add(lbl);
- //PageControls.Add(pc);
- AccordionPanes.Add(ap);
- }
- }
- }
- LoadUI();
- }
- private CrystalReportsParameterControls_DiscreteValueStringWithDefaults LoadDiscreteValueStringWithDefaults()
- {
- CrystalReportsParameterControls_DiscreteValueStringWithDefaults myControl = new CrystalReportsParameterControls_DiscreteValueStringWithDefaults();
- myControl = (CrystalReportsParameterControls_DiscreteValueStringWithDefaults)LoadControl("~/CrystalReportsParameterControls/DiscreteValueStringWithDefaults.ascx");
- return myControl;
- }
- private CrystalReportsParameterControls_DiscreteValueDate LoadDiscreteDate()
- {
- CrystalReportsParameterControls_DiscreteValueDate myControl = new CrystalReportsParameterControls_DiscreteValueDate();
- myControl = (CrystalReportsParameterControls_DiscreteValueDate)LoadControl("~/CrystalReportsParameterControls/DiscreteValueDate.ascx");
- return myControl;
- }
- public ParameterFieldDefinitions GetParameterSettings
- {
- get
- {
- return m_ParameterFieldDefinitions;
- }
- }
- public void ApplyParameterValues()
- {
- foreach (BaseCrystalReportParameterControl uc in PageControls)
- {
- uc.ApplyParameterValues();
- }
- }
- }