Problems dsplaying User Controls

G

Guest

Hi,
I have a User Control that I want to display at the top and bottom of the
web form. I have two PlaceHolders controls at the top and bottom of the page
and I'm loading the control programmatically in the placeholder control:

Control ctl = LoadControl("MyControl.ascx");
plhTop.Controls.Add(ctl);
plhBottom.Controls.Add(ctl);

The problem is that only plhBottom is displayed. If I change places of
plhTop and plhBottom in the code:

Control ctl = LoadControl("MyControl.ascx");
plhBottom.Controls.Add(ctl);
plhTop.Controls.Add(ctl);

then only plhTop is displayed.

Why doesn't this code display both controls?
Thank you.
 
K

Karl

You can't have the same instance of a control in two separate locations.
Create a 2nd control

Control c1 = LoadControl("MyControl.ascx");
Control c2 = LoadControl("MyControl.ascx");
plhTop.Controls.Add(c1);
plhBottom.Controls.add(c2);


Karl
 

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,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top