Add same control to different controls

  • Thread starter Thread starter Andrew Jocelyn
  • Start date Start date
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
 
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.
 
Back
Top