PC Review


Reply
Thread Tools Rate Thread

WebControls' text properties are all over the place

 
 
TH
Guest
Posts: n/a
 
      16th Jun 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
 
      19th Jun 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
Rate This Thread
Rate This Thread:

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
PowerPoint keeps crashing, over and over and over and over MB Microsoft Powerpoint 1 12th Jan 2010 08:00 PM
BCM shutting down over and over and over and over TheMurf Microsoft Outlook BCM 1 9th Mar 2007 03:32 PM
Getting same message over and over and over and over each day =?Utf-8?B?Z29pbmJhdHR5?= Microsoft Outlook 1 18th Nov 2005 10:52 PM
XP Login Over & Over & Over & Over Desert Rat Windows XP Help 1 30th Oct 2004 02:37 AM
Outlook 2002 crashes over and over and over and over and over and over typoo Microsoft Outlook Discussion 5 7th Mar 2004 08:12 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:15 PM.