473,387 Members | 1,757 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.

Howto Iterate thru a control collection ?

I've got a webform and many controls on it. I would like to iterate thru the
control collection to get all the textboxes control to let me change the text
property. Here is my code...for unknown reason, this loop iterates only 3
times! Help please! Thanks!

Dim Control As Web.UI.Control
Dim TextBox As System.Web.UI.WebControls.TextBox

For Each Control In Controls
If TypeOf (Control) Is System.Web.UI.WebControls.TextBox Then
TextBox = CType(Control, TextBox)
TextBox.Text = ""
End If
Next
Jul 21 '05 #1
2 5323
"Simon" <Si***@discussions.microsoft.com> wrote in message
news:CC**********************************@microsof t.com...
I've got a webform and many controls on it. I would like to iterate thru
the
control collection to get all the textboxes control to let me change the
text
property. Here is my code...for unknown reason, this loop iterates only 3
times! Help please! Thanks!
By any chance are any of your controls contained in other controls? If so,
you will have to modify the code to something like this:

ClearTextBoxes(Me.Controls)

Public Sub ClearTextBoxes(ControlCollection controls)
Dim Control As Web.UI.Control
Dim TextBox As System.Web.UI.WebControls.TextBox

For Each Control In controls
If TypeOf (Control) Is System.Web.UI.WebControls.TextBox Then
TextBox = CType(Control, TextBox)
TextBox.Text = ""
Else
ClearTextBoxes(Control.Controls)
End If
Next
End Sub

Dim Control As Web.UI.Control
Dim TextBox As System.Web.UI.WebControls.TextBox

For Each Control In Controls
If TypeOf (Control) Is System.Web.UI.WebControls.TextBox Then
TextBox = CType(Control, TextBox)
TextBox.Text = ""
End If
Next

Jul 21 '05 #2
Simon,

The find does the trick

\\\
Dim frm As Control = Me.FindControl("Form1")
For Each ctl as Control In frm.Controls
Dim tb As TextBox
If TypeOf ctl Is TextBox Then
tb = DirectCast(ctl, TextBox)
tb.Text = ""
End If
Next
///

I hope this helps,

Cor
Jul 21 '05 #3

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

Similar topics

5
by: Mateo | last post by:
Let's say that I have panel control which is container control, and I need to access every child control inside panel control from JScript. I have this line of JS code: var oCollection =...
0
by: dantheman | last post by:
Hi, i'm doing a programe in a few languages so i've found this code that iterates tru the forms controls and returns there names but the problem is after re-parenting the controls to optimize...
2
by: JDavies | last post by:
Hi All I am dynamically Creating DropDownList boxes for a Survey form. These DropdownLists are added to Table Cells programatically. I tried to loop thru the controls on the form but it doesnt...
2
by: James Doran | last post by:
Hello, I'd like to iterate through each Page of my ASP.NET project from within a Custom web control and access the Page.Controls collection. I've tried using Reflection on the web project...
1
by: Dan Sikorsky | last post by:
How do you recursively iterate thru each collection on each form on a web page and find each web control? -- Thank you kindly, Dan Sikorsky BAB, BScE, MSC
7
by: Rich | last post by:
Hello, I have a form with 5 textboxes named txt0, txt1, txt2, txt3, tx4. In VB6 I could iterate through these with For i = 0 to 4 debug.print Me.controls("txt" & i).Name Next
7
by: Dan Sikorsky | last post by:
How do you iterate thru a dataset to change money fields to a different value? Here's what I have. My dataset is filled directly from a stored procedure. ' Create Instance of Connection and...
2
by: Simon | last post by:
I've got a webform and many controls on it. I would like to iterate thru the control collection to get all the textboxes control to let me change the text property. Here is my code...for unknown...
1
by: Dean Slindee | last post by:
I have a toolStripDropDownButton with child toolStripDropDownMenuItems. I would like to iterate thru the toolStripDropDownMenuItems and look at the menuitems and discard the separators. Problem...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
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.