Using User Controls in a Composite Control?

I

i. dzhugashvili

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
 
T

Thomas Johansen

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)
 
I

i. dzhugashvili

Thomas Johansen said:
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)



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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top