Iterating through controls (VB)

Discussion in 'ASP .Net' started by Jeremy, Jul 31, 2003.

  1. Jeremy

    Jeremy Guest

    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
    Jeremy, Jul 31, 2003
    #1
    1. Advertising

  2. Jeremy

    Marina Guest

    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" <> wrote in message
    news:%...
    > 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
    >
    >
    >
    Marina, Jul 31, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Milsnips
    Replies:
    4
    Views:
    2,332
    Scott M.
    Oct 30, 2004
  2. Dave H
    Replies:
    5
    Views:
    524
    Walter Wang [MSFT]
    Jun 30, 2006
  3. RSH
    Replies:
    1
    Views:
    406
    Rob MacFadyen
    Sep 12, 2006
  4. DrTeeth
    Replies:
    1
    Views:
    381
    DrTeeth
    Jul 9, 2008
  5. carl
    Replies:
    5
    Views:
    2,320
    James Kanze
    Nov 25, 2009
Loading...

Share This Page