Iterating through controls (VB)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jeremy

    Iterating through controls (VB)

    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("Fo rm2")

    For Each ctrl In frm.Controls

    If TypeOf ctrl Is TextBox Then

    CType(ctrl, TextBox).CssCla ss = cssTextbox

    End If

    Next



  • Marina

    #2
    Re: Iterating through controls (VB)

    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" <wwwgeek@comcas t.net> wrote in message
    news:%23cv1HQ3V DHA.2156@TK2MSF TNGP11.phx.gbl. ..[color=blue]
    > I have been trying to iterate through the controls on my form and preset[/color]
    all[color=blue]
    > 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[/color]
    in[color=blue]
    > 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("Fo rm2")
    >
    > For Each ctrl In frm.Controls
    >
    > If TypeOf ctrl Is TextBox Then
    >
    > CType(ctrl, TextBox).CssCla ss = cssTextbox
    >
    > End If
    >
    > Next
    >
    >
    >[/color]


    Comment

    Working...