473,387 Members | 3,801 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

WebControls' text properties are all over the place

TH
Could anyone please explain the bizarre and utterly infuriating effect
I am observing while adding controls programmatically? I've reduced the
problem to the following code:

<form id=Form1 method=post runat="server">
<asp:label id=Label1 runat="server"/><BR>
<asp:Label id=Label2 runat="server"/><BR>
<asp:Button id=Button1 runat="server" Text="Button"/><BR>
<asp:Button id=Button2 runat="server" Text="Button"/><BR>
<asp:Button id=Button3 runat="server" Text="Button"/><BR>
<asp:Button id=Button4 runat="server" Text="Button"/><BR>
<asp:Button id=Button5 runat="server" Text="Button"/><BR>
</form>

private ArrayList MyLabels = new ArrayList();

private void Page_Load(object sender, System.EventArgs e)
{
WalkControls(this);
foreach(Label label in MyLabels)
{
label.Text = label.ID + " " + DateTime.Now.ToString();
label.Parent.Controls.AddAt(label.Parent.Controls. IndexOf(label),
new TextBox());
}
}

private void WalkControls(Control control)
{
if (control is Label)
{
Label label = control as Label;
MyLabels.Add(label);
}
foreach(Control c in control.Controls)
{
WalkControls(c);
}
}

I.e. I'm recursively looking for Labels and adding them to an ArrayList
where they are later given a sibling TextBox. I'm also setting the
label text here to illustrate the problem. The buttons shouldn't be
doing anything.

On each postback, the first button's text property somehow acquires the
text from the second label's previous text value, and each subsequent
button picks up the previous text value of the button above.

Can anyone please help? It's driving me mad.
Thanks, Tony.

Jun 16 '06 #1
1 1269
TH
TH wrote:
Could anyone please explain the bizarre and utterly infuriating effect
I am observing while adding controls programmatically?


I'll take that as a no then.

Does anyone actualy use usenet any more?

Jun 19 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Rodrigo DeJuana | last post by:
Howdy, I'm new to this .net stuff and really have little to no training. Im trying to create a new page for a web form, so i have been pretty much jsut coping code. I having some issue with...
2
by: Don Wash | last post by:
Hi There! I'm creating my website with ASP.NET + XHTML, which means I will strictly adhere the XHTML standards for my web page output. I use Panel or PlaceHolder WebControls to place...
1
by: Rog | last post by:
Hello, Yesterday I downloaded IEwebcontrols.exe and TreeviewControl.msi from http://msdn.microsoft.com/library/default.asp? url=/library/en-us/dnaspp/html/aspnet-...
3
by: Dotnet Gruven | last post by:
I've built a WebForm with a Table added dynamically in Page_Load when IsPostBack is false. The table includes a couple of TextBoxes, RadioButtonLists and CheckboxLists. On postback, those...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.