locked
Custom controls containing child controls RRS feed

  • Question

  • User622034594 posted

    Hi Folks,

    I am trying to create an asp.net custom control that acts as a hosting container for any other controls, similar to the existing ‘Panel’ control. Basically, I need to build a web control that groups a bunch of other controls. It will consist of a header and a body pane, similar to a normal window in desktop application. The header will contain some simple text and some JavaScript driven code that shows/hides the body pane. The body pane simply hosts any number of other controls.


    +------------------------------------------------------+
    | User Details Show/Hide |
    +------------------------------------------------------+
    | Name:[Eric ] |
    | Address:[Some where] |
    | Date of Birth:[01/01/1980] |
    | |
    | (any other fields goes on) |
    | |
    | |
    +------------------------------------------------------+

    Ideally I want to create a control that packs the whole thing together, so at design time I could use the following markup.

    <myCtl:SuperContainer runat=”server” Title=”User Details”>

          <asp:label id=”lblName” runat=”server” text=”Name:”/>

          <asp:textbox id=”txtName” runat=”server”/>

          <asp:label id=”lblDOB” runat=”server” text=”Date of Birth:”/>

          <asp:textbox id=”txtDOB” runat=”server”/>

          (…other controls definition…)

    </myCtl:SuperContainer>


    I plan to include two panels in my control, one for the header and another one for the body, but as you can see, the key issue is to find a way to ‘divert’ the child controls that are defined in the markup to the body panel, instead of the default parent container. I feel it can be some how simply override (manipulate) the control property, but don’t know how to properly do so.

    Can any one give some idea about how to implement this ‘SuperContainer’ control?

    Many thank,

    Eric

    Sunday, December 13, 2009 9:27 PM

Answers

  • User1611391320 posted

    u need to make a function inside custom control that can add controls in order inside it

     

    and from code u would simply call that function like

    custcontrolid.addcontrolfun(Control);

    and it would append in the body of that control

    similarly u can add other controls.

     

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, December 13, 2009 11:43 PM