Assign the same value to two or more controls at the same time
-
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
orLabel
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? -
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
orLabel
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?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)
-
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)
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)
-
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
orLabel
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?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