By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,929 Members | 631 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,929 IT Pros & Developers. It's quick & easy.

Iterating through controls (VB)

P: n/a
I have been trying to iterate through the controls on my form and preset all
textboxes to a cssClass. Unfortunately, I have been unable to figure out
how to recursively move through sub-controls and all of my textboxes are in
asp panels. The code I have can see the panels but not what is in them.

Help please.

Current code:
Dim frm As Control

Dim ctrl As Control

frm = FindControl("Form2")

For Each ctrl In frm.Controls

If TypeOf ctrl Is TextBox Then

CType(ctrl, TextBox).CssClass = cssTextbox

End If

Next

Nov 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
You basically have to call your function on each of the controls in the
Controls collection of the current control. When you get to a control with
no children - then it's not a container control, and you can check if it's a
textbox, etc.

"Jeremy" <ww*****@comcast.net> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
I have been trying to iterate through the controls on my form and preset all textboxes to a cssClass. Unfortunately, I have been unable to figure out
how to recursively move through sub-controls and all of my textboxes are in asp panels. The code I have can see the panels but not what is in them.

Help please.

Current code:
Dim frm As Control

Dim ctrl As Control

frm = FindControl("Form2")

For Each ctrl In frm.Controls

If TypeOf ctrl Is TextBox Then

CType(ctrl, TextBox).CssClass = cssTextbox

End If

Next

Nov 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.