Iterating through controls (VB)

J

Jeremy

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
 
M

Marina

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top