473,612 Members | 2,115 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 programmaticall y? 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(objec t sender, System.EventArg s e)
{
WalkControls(th is);
foreach(Label label in MyLabels)
{
label.Text = label.ID + " " + DateTime.Now.To String();
label.Parent.Co ntrols.AddAt(la bel.Parent.Cont rols.IndexOf(la bel),
new TextBox());
}
}

private void WalkControls(Co ntrol control)
{
if (control is Label)
{
Label label = control as Label;
MyLabels.Add(la bel);
}
foreach(Control c in control.Control s)
{
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 1277
TH
TH wrote:
Could anyone please explain the bizarre and utterly infuriating effect
I am observing while adding controls programmaticall y?


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
2906
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 some textboxes not updating when i a hit save. for example I have this code in my aspx.cs file: declared:
2
3614
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 dynamically created <div></div> contents to my web pages. But the problem arises when because Panel and PlaceHolder WebControls do extra work with <span> tags as follows...
1
1706
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- usingtreeviewiewebcontrol.asp
3
2530
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 controls are not present nor their valves in Request.Form.AllKeys.
0
8162
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8105
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8605
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8246
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8415
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7039
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5532
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4109
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2550
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.