Using User Controls in a Composite Control?

Ask a Question related to ASP.NET Building Controls, Design and Development.

  1. #1

    Default Using User Controls in a Composite Control?

    Is it possible to contain one or more User Controls (.ascx files) in a
    Composite Control?

    I start with a simple Composite Control sample that displays a plain
    CheckBox control that works fine, but when I switch this Checkbox with
    my User Control the page is displayed without my control. I verified
    that my control is being added the form's Controls collection.

    Am I missing something here? Can anyone point me to any resources or
    samples (especially in C#)? I searched the newgroups and the web (and
    of course MSDN) and I haven't found an examples or any reasons why I
    can't do this.

    Any advice?
    -id
    i. dzhugashvili Guest

  2. Similar Questions and Discussions

    1. Maintaining state in programmatically created composite user controls
      Hi I'm writing a timesheet application in ASP.NET (framework 1.1, VS 2003) that includes a user control to manage project time allocation...
    2. Composite Web Control and saving user changes on child controls.
      Okay, having the same problem many others are having. Here is a simple example I cannot get to work: -- using C# a) Created an ASP.NET Web...
    3. using javascript in User controls to access server controls of the user control
      Hello all, I have an asp.net textbox (named txtHidden) and an HtmlButton(named btnAction). I wanted to write a javascript function which will get...
    4. Viewstate lost in child controls of a composite control
      Hi, 1) You should implement INamingContainer interface 2) You shouldn't change child control's place in the Controls collection after they're...
    5. Custom Composite Control, child User-controls loosing view state
      I've created composite custom control which dynamically creates and arranges it's child controls based on some xml data. Beside the simple web form...
  3. #2

    Default Re: Using User Controls in a Composite Control?

    Can you please show us the relevant code, I am especially interested in the
    section where you add the control to the Control hierarchy (I'm assuming you
    do this programatically as you say you are developing a composite control)

    --
    Regards,
    Thomas Johansen (aka. Aylar)

    i. dzhugashvili <idzhugashvili@hotmail.com> wrote:
    > Is it possible to contain one or more User Controls (.ascx files) in a
    > Composite Control?
    >
    > I start with a simple Composite Control sample that displays a plain
    > CheckBox control that works fine, but when I switch this Checkbox with
    > my User Control the page is displayed without my control. I verified
    > that my control is being added the form's Controls collection.
    >
    > Am I missing something here? Can anyone point me to any resources or
    > samples (especially in C#)? I searched the newgroups and the web (and
    > of course MSDN) and I haven't found an examples or any reasons why I
    > can't do this.
    >
    > Any advice?
    > -id

    Thomas Johansen Guest

  4. #3

    Default Re: Using User Controls in a Composite Control?

    "Thomas Johansen" <aylar@aspalliance.com> wrote in message news:<#gnb0Ff#DHA.3536@TK2MSFTNGP10.phx.gbl>...
    > Can you please show us the relevant code, I am especially interested in the
    > section where you add the control to the Control hierarchy (I'm assuming you
    > do this programatically as you say you are developing a composite control)
    >
    > --
    > Regards,
    > Thomas Johansen (aka. Aylar)
    >
    > i. dzhugashvili <idzhugashvili@hotmail.com> wrote:
    > > Is it possible to contain one or more User Controls (.ascx files) in a
    > > Composite Control?
    > >
    > > I start with a simple Composite Control sample that displays a plain
    > > CheckBox control that works fine, but when I switch this Checkbox with
    > > my User Control the page is displayed without my control. I verified
    > > that my control is being added the form's Controls collection.
    > >
    > > Am I missing something here? Can anyone point me to any resources or
    > > samples (especially in C#)? I searched the newgroups and the web (and
    > > of course MSDN) and I haven't found an examples or any reasons why I
    > > can't do this.
    > >
    > > Any advice?
    > > -id


    Hi Thomas,

    For my test I'm trying to create an instance of my user control and
    add it to the Controls collection in CreateChildControls() (see the
    snippet below). Now, if I use a standard webcontrol (like a CheckBox)
    in place of MyUserControl below, it works - I see the Checkbox on the
    page that uses my composite control.

    Here's the snippet of CreateChildControls:
    protected override void CreateChildControls() {
    MyUserControl uc = new MyUserControl();
    Controls.Add(uc);
    }

    The class this code is in inherits
    System.Web.UI.WebControls.WebControl and implements INamingContainer.

    I also tried creating an instance of my user control using
    TemplateControl.LoadControl, but I wasn't quite able to get this to
    work.


    I feel I'm getting close. Additional searching on using User Controls
    in Composite Controls shows me that it's possible but I haven't found
    a single example. Any advice would be greatly appreciated!

    Thanks
    -id
    i. dzhugashvili Guest

  5. #4

    Default Re: Using User Controls in a Composite Control?

    Quote Originally Posted by i. dzhugashvili View Post
    "Thomas Johansen" <aylar@aspalliance.com> wrote in message news:<#gnb0Ff#DHA.3536@TK2MSFTNGP10.phx.gbl>...



    Hi Thomas,

    For my test I'm trying to create an instance of my user control and
    add it to the Controls collection in CreateChildControls() (see the
    snippet below). Now, if I use a standard webcontrol (like a CheckBox)
    in place of MyUserControl below, it works - I see the Checkbox on the
    page that uses my composite control.

    Here's the snippet of CreateChildControls:
    protected override void CreateChildControls() {
    MyUserControl uc = new MyUserControl();
    Controls.Add(uc);
    }

    The class this code is in inherits
    System.Web.UI.WebControls.WebControl and implements INamingContainer.

    I also tried creating an instance of my user control using
    TemplateControl.LoadControl, but I wasn't quite able to get this to
    work.


    I feel I'm getting close. Additional searching on using User Controls
    in Composite Controls shows me that it's possible but I haven't found
    a single example. Any advice would be greatly appreciated!

    Thanks
    -id
    Hi dzhugashvili

    I am stuck with the exact same problem. The ascx control dosent render on the final output. Did u find a way out?
    Unregistered Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139