Using User Controls in a Composite Control?

Discussion in 'ASP .Net Building Controls' started by i. dzhugashvili, Feb 23, 2004.

  1. 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, Feb 23, 2004
    #1
    1. Advertising

  2. 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 <> 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, Feb 23, 2004
    #2
    1. Advertising

  3. "Thomas Johansen" <> wrote in message news:<#gnb0Ff#>...
    > 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 <> 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, Feb 24, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. sleigh
    Replies:
    1
    Views:
    2,707
    sleigh
    Feb 12, 2004
  2. Faizan Ahmed
    Replies:
    1
    Views:
    301
    John Saunders
    Jan 4, 2005
  3. Chad
    Replies:
    0
    Views:
    237
  4. Faizan Ahmed
    Replies:
    1
    Views:
    377
    John Saunders
    Jan 4, 2005
  5. Mike

    Composite vs non composite Controls

    Mike, Mar 10, 2005, in forum: ASP .Net Web Controls
    Replies:
    4
    Views:
    272
    Sundararajan
    Mar 11, 2005
Loading...

Share This Page