Add same control to different controls

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Andrew Jocelyn

    Add same control to different controls


    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.Co ntrols.Add(lb);
    Response.Write( PlaceHolder1.Ha sControls().ToS tring()); // true
    PlaceHolder2.Co ntrols.Add(lb);
    Response.Write( PlaceHolder1.Ha sControls().ToS tring()); // false


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

    Thanks
    Andrew


  • Riki

    #2
    Re: Add same control to different controls

    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.

    --
    Riki

    "Andrew Jocelyn" <j055@newsgroup s.nospamwrote in message
    news:uf1wvr$xIH A.420@TK2MSFTNG P02.phx.gbl...
    >
    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.Co ntrols.Add(lb);
    Response.Write( PlaceHolder1.Ha sControls().ToS tring()); // true
    PlaceHolder2.Co ntrols.Add(lb);
    Response.Write( PlaceHolder1.Ha sControls().ToS tring()); // false
    >
    >
    In real live the Label with be a custom control with child controls. What
    should I do?
    >
    Thanks
    Andrew
    >

    Comment

    • =?Utf-8?B?WWFua2VlIEltcGVyaWFsaXN0IERvZw==?=

      #3
      RE: Add same control to different controls

      create a second label control and add it.
      --
      Share The Knowledge. I need all the help I can get and so do you!


      "Andrew Jocelyn" wrote:
      >
      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.Co ntrols.Add(lb);
      Response.Write( PlaceHolder1.Ha sControls().ToS tring()); // true
      PlaceHolder2.Co ntrols.Add(lb);
      Response.Write( PlaceHolder1.Ha sControls().ToS tring()); // false
      >
      >
      In real live the Label with be a custom control with child controls. What
      should I do?
      >
      Thanks
      Andrew
      >
      >
      >

      Comment

      Working...