Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > WebControls' text properties are all over the place

Reply
Thread Tools

WebControls' text properties are all over the place

 
 
TH
Guest
Posts: n/a
 
      06-16-2006
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.

 
Reply With Quote
 
 
 
 
TH
Guest
Posts: n/a
 
      06-19-2006
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?

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
VOIP over VPN over TCP over WAP over 3G Theo Markettos UK VOIP 2 02-14-2008 03:27 PM
Not able to copy all properties using properties.putAll() method. Sonal Java 3 12-07-2007 03:08 AM
pointer to type all over the place Gary Wessle C++ 1 11-30-2006 10:38 PM
Snypatics PS/2 Touchpad Jumping all over the place =?Utf-8?B?cGF1bGNy?= Windows 64bit 0 10-22-2006 01:49 AM
perl lib all over the place Sam Perl Misc 5 09-22-2003 01:10 AM



Advertisments