Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Assign the same value to two or more controls at the same time

Assign the same value to two or more controls at the same time

Scheduled Pinned Locked Moved ASP.NET
csharpasp-netcomhelpquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Paul Watson
    wrote on last edited by
    #1

    Before I wander off and re-invent the wheel I thought it best to ask if there already is a way to do what I want. Say you have two Literal or Label controls on your page and they always display the same value. Right now I have to create them seperately with different IDs and assign the value seperately to each. Is there a built in method of doing away with the two IDs and assigning the value to both at the same time? If not then I am off to go create an ASP.NET control that does just that. p.s. I want to do it from the code-behind so <%=Value%> won't help, thanks. regards, Paul Watson Bluegrass South Africa Anna-Jayne Metcalfe wrote: "Cynicism has it's place in life - but it should be kept well away from your inner self." Crikey! ain't life grand?

    C B 2 Replies Last reply
    0
    • P Paul Watson

      Before I wander off and re-invent the wheel I thought it best to ask if there already is a way to do what I want. Say you have two Literal or Label controls on your page and they always display the same value. Right now I have to create them seperately with different IDs and assign the value seperately to each. Is there a built in method of doing away with the two IDs and assigning the value to both at the same time? If not then I am off to go create an ASP.NET control that does just that. p.s. I want to do it from the code-behind so <%=Value%> won't help, thanks. regards, Paul Watson Bluegrass South Africa Anna-Jayne Metcalfe wrote: "Cynicism has it's place in life - but it should be kept well away from your inner self." Crikey! ain't life grand?

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      ASP.NET does not support two controls with the same ID. If you turn the page tracing on you'll get error messages. I think it doesn't complain with page tracing off - but the results may be unexpected. --Colin Mackay--

      "In the confrontation between the stream and the rock, the stream always wins - not through strength but perseverance." (H. Jackson Brown)

      C 1 Reply Last reply
      0
      • C Colin Angus Mackay

        ASP.NET does not support two controls with the same ID. If you turn the page tracing on you'll get error messages. I think it doesn't complain with page tracing off - but the results may be unexpected. --Colin Mackay--

        "In the confrontation between the stream and the rock, the stream always wins - not through strength but perseverance." (H. Jackson Brown)

        C Offline
        C Offline
        Colin Angus Mackay
        wrote on last edited by
        #3

        Oops! I mis-read your original post and I answered a question you didn't ask. :-o Yes, I think creating a composite control would be the best solution for this. I can't think of any other way to do what you are wanting to do. Regards, Colin. --Colin Mackay--

        "In the confrontation between the stream and the rock, the stream always wins - not through strength but perseverance." (H. Jackson Brown)

        1 Reply Last reply
        0
        • P Paul Watson

          Before I wander off and re-invent the wheel I thought it best to ask if there already is a way to do what I want. Say you have two Literal or Label controls on your page and they always display the same value. Right now I have to create them seperately with different IDs and assign the value seperately to each. Is there a built in method of doing away with the two IDs and assigning the value to both at the same time? If not then I am off to go create an ASP.NET control that does just that. p.s. I want to do it from the code-behind so <%=Value%> won't help, thanks. regards, Paul Watson Bluegrass South Africa Anna-Jayne Metcalfe wrote: "Cynicism has it's place in life - but it should be kept well away from your inner self." Crikey! ain't life grand?

          B Offline
          B Offline
          Bill Priess
          wrote on last edited by
          #4

          There is a slightly easier way without having the overhead of creating a composite control. Add a PlaceHolder to your page. Then, in the code behind: protected System.Web.UI.WebControl.PlaceHolder plHolder; private void Page_Load(object Sender, EventArgs e) { using (Label lbl = new Label()) { lbl.Text = someVariable; plHolder.Control.AddAt(0, lbl); } using (LiteralControl lc = new LiteralControl()) { lc.Text = someVariable; plHolder.Control.AddAt(1, lc); } } This should acheive the results that you want without a lot of overhead. :) HTH, Bill P. Oakland, CA

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups