473,289 Members | 1,875 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,289 software developers and data experts.

Controls.Count, Controls.IsSynchronized, and Controls.SyncRoot

I have a section of my code in which I need to know how many child controls
a control has. Right now Controls.Count is returning the wrong value, which
I realize is because Controls.IsSynchronized is False. After spending a few
hours trying to figure out how I could determine the number of child
controls, I discovered that Controls.SyncRoot is somehow involved, but I had
trouble understanding exactly what I need to do. Could somebody please help
me? Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/
Sep 4 '07 #1
4 1953
you are on the wrong track. unless you are spinning up new threads
during a page request and those threads are adding child controls, there
is no need to use Controls.IsSynchronized.

Controls.Count is only your controls immediate count. each of its child
controls can have children. also when you test it, all the children may
not be created.

what makes you think the count is wrong?

-- bruce (sqlwork.com)
Nathan Sokalski wrote:
I have a section of my code in which I need to know how many child controls
a control has. Right now Controls.Count is returning the wrong value, which
I realize is because Controls.IsSynchronized is False. After spending a few
hours trying to figure out how I could determine the number of child
controls, I discovered that Controls.SyncRoot is somehow involved, but I had
trouble understanding exactly what I need to do. Could somebody please help
me? Thanks.
Sep 4 '07 #2
I have a section of my code in which I need to know how many child controls
a control has. Right now Controls.Count is returning the wrong value, which
Just a couple of points to consider,,,,

1) Controls.Count is the count of only immediate children, not the
grand-children.

2) Plain text (sometimes even a space), which apparently may not look
like control, become controls. To add complexity, it is not guaranteed
how many controls would this text divide into.

Sep 5 '07 #3
I know the count is wrong, because first of all, I used the Controls.Add()
method to add multiple Controls, so I know that there are more than 1. Also,
I did a Debug and looked at the Controls.Count property immediately before
and immediately after adding the control, and it had changed from 1 to 2.
And yet, on the next postback that same Control had a Controls.Count value
of 1 again instead of remaining at 2. This did not make since to me, so the
only possibility I could come up with (although I admit I have very little
experience with threads and synchronization, even though this is not a
multi-threaded application) was that it had something to do with all the
synchronization stuff I found while trying to find an answer. I'm totally
confused about this now. Any ideas?
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

"bruce barker" <no****@nospam.comwrote in message
news:ee*************@TK2MSFTNGP04.phx.gbl...
you are on the wrong track. unless you are spinning up new threads during
a page request and those threads are adding child controls, there is no
need to use Controls.IsSynchronized.

Controls.Count is only your controls immediate count. each of its child
controls can have children. also when you test it, all the children may
not be created.

what makes you think the count is wrong?

-- bruce (sqlwork.com)
Nathan Sokalski wrote:
>I have a section of my code in which I need to know how many child
controls a control has. Right now Controls.Count is returning the wrong
value, which I realize is because Controls.IsSynchronized is False. After
spending a few hours trying to figure out how I could determine the
number of child controls, I discovered that Controls.SyncRoot is somehow
involved, but I had trouble understanding exactly what I need to do.
Could somebody please help me? Thanks.

Sep 5 '07 #4
And yet, on the next postback that same Control had a Controls.Count value
of 1 again instead of remaining at 2.
Dynamically added controls do not survive post back. They need to be
added again in every postback.

Sep 5 '07 #5

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

Similar topics

2
by: Matt | last post by:
Hello all, I have written a collection class that implements IList. The class currently uses an ArrayList for its internal storage. I am somewhat confused as to how I should implement the...
4
by: chrisben | last post by:
Hi I often use Queue.Synchronized method to create a queue for multithread writing. I also know I could use SyncRoot and lock to write Queue. Could anyone here please explain to me the pros and...
4
by: Steve Long | last post by:
Can anybody help me out with a code sample or other info on how to implement SyncRoot on a NameValueCollection? Or, is there another .NET class that does this for me with the same functionality as...
6
by: Scott Mueller | last post by:
I have a question about simple binding: (please forgive any syntax errors... I am at home, where I do not have Vb.Net installed, and I rely far too much on Vb's intellisense!) If I have two...
5
by: Jacob | last post by:
Hi there, Say I have an ArrayList named list. What's the difference between using lock(list) { .... } and lock(list.SyncRoot) { .... }
15
by: Arpan | last post by:
Consider the following code which retrieves data from a SQL Server 2005 DB table & displays it in a DataGrid: <script runat="server"> Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs)...
2
by: =?Utf-8?B?TWluIFlvbmc=?= | last post by:
I'm not sure if I've just lost it but, I no longer see the property SyncRoot on a Queue. I see that it's a member of the ICollection Base Object, but it's not exposed. Was this intended? Besides...
3
by: Chad Scharf | last post by:
Ok, as silly as it may sound, I have a situation where I am creating a CompositeControl in ASP.NET 2.0, C#. I have the following code in the CreateChildControls() method that build the control's...
2
by: eBob.com | last post by:
I was changing some code in a multi-threaded application today and noticed that it was not locking where it really needed to be locking. The Sub was already working with an array so I just stuck a...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.