locked
how to write nested custom web control(example an Accordian control)? RRS feed

  • Question

  • User-1221966532 posted

     Hi,

     I have written an Accordion like custom web control, with similar behaviour as the one form the AJAX control toolkit. All would be ok, if the Header/Content nested AccordionPane container tags would render its control collection, placed between the opening and closing tags in the view designer. All I get is an empty <div></div> for the Header and the Content

    <div id="Accordion1" class="AccordionBorder">
        <div id="Accordion1_AccordionPane1">
            <div class="HeaderCssClass">
            <!-- content should be here, but it is empty -->
            </div>

            <div class="ContentCssClass">
             <!-- content should be here, but it is empty -->
            </div>
        </div>
    </div>

    I have set the following attributes:

    [PersistChildren(true)]
    [ParseChildren(false)]
    [ToolboxItem(false)]
    public class AccordionPaneContent : WebControl, INamingContainer
    {

            public AccordionPaneContent(AccordionPane parent, Enum.PANE_CONTENT_TYPE contentType)
            {
                EnsureChildControls();
               
                m_Parent = parent;
                m_ContentType = contentType;
            }

    }

    [ToolboxData("<{0}:AccordionPane runat=\"server\"></{0}:AccordionPane>")]
    public class AccordionPane : WebControl, INamingContainer
    {

            private AccordionPaneContent m_Header;
            private AccordionPaneContent m_Content;

            PersistenceMode(PersistenceMode.InnerProperty)]
            [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
            public AccordionPaneContent Header

            {

                  get{...} set{...}

            }

            PersistenceMode(PersistenceMode.InnerProperty)]
            [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
            public AccordionPaneContent Content

            {

                  get{...} set{...}

            }

     

            protected override void CreateChildControls()
            {
                EnsureChildControls();
                base.CreateChildControls();

                m_Header = new AccordionPaneContent(this, Enum.PANE_CONTENT_TYPE.Header);
                m_Content = new AccordionPaneContent(this, Enum.PANE_CONTENT_TYPE.Content);

                this.Controls.Add(m_Header);
                this.Controls.Add(m_Content);
            }

    }

     

    I have written the Accordian control a bit differently than the AJAX control toolkit one, ommiting the Template. Can anyone tell me what could go wrong. Obviously the code above is only a pseudo code, but it contains the main area I have changed/overriden.

    Tuesday, June 16, 2009 10:41 PM

Answers

  • User-1221966532 posted

     Hi Allen,

     thanks  for your quick response and willingness to help, fortunately I worked out what went wrong, so I am delighted.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, June 19, 2009 8:32 AM

All replies

  • User-2106054853 posted

    Hi,

    Please upload a demo project to:http://skydrive.live.com/

    and paste the download link here for me to repro.

    Thursday, June 18, 2009 4:53 AM
  • User-1221966532 posted

     Hi Allen,

     thanks  for your quick response and willingness to help, fortunately I worked out what went wrong, so I am delighted.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, June 19, 2009 8:32 AM