Add same control to different controls

A

Andrew Jocelyn

Hi

Maybe it's because it's Friday afternoon but I can't work out how to simply
use the same Label control in two different PlaceHolder controls. This is
what happens. When I add the Label to the second PlaceHolder it's removed
from the first. I want any changes to the Label to be reflected in both
PlaceHolders.

Label lb = new Label();
lb.Text = "Label";
PlaceHolder1.Controls.Add(lb);
Response.Write(PlaceHolder1.HasControls().ToString()); // true
PlaceHolder2.Controls.Add(lb);
Response.Write(PlaceHolder1.HasControls().ToString()); // false


In real live the Label with be a custom control with child controls. What
should I do?

Thanks
Andrew
 
R

Riki

This is how ASP.NET controls behave.
You can't add them twice.

You'll need to write some code that updates both labels, and do all updates
through that code.
 

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,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top