Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loop thru controls and set visible 1

Status
Not open for further replies.

Olavxxx

Programmer
Sep 21, 2004
1,134
NO
Hi,

I am looping thru a textlist, based on a variable.
The asp.net then opens the file (same filename as variable).

The file has one line per item, like so:
blah
foo
bar

The thing is that if I have the inputs blah, foo, bar, etc. I want the fields which correspond to be set to visible.

I think, however, that I might be "attacking" at the wrong end. Maybe I could enumerate controls in the web-form, loop thru them?

I want some pointers, tips/examples, if anyone knows anything about this sort of action.

The general idea, is that I'll have all the controls in the web-form,so the users can edit textfiles to config which fields should be visible for which input-type.

My idea was
Code:
    Private Function ToggleFields(ByVal fld As TextBox)
        fld.Visible = True
    End Function

My problem, however, is that it's not possible to cast the variable (from the loop) to a textbox for the byval value? If it where possible, this would be very easy!

Hope someone can help!

Olav Alexander Mjelde
Admin & Webmaster
 
To loop through all the controls on a page, you'll have to use a recursive function. A simple example of this would be:
Code:
 Private  Sub SetTextBoxBackColor(ByVal Page As Control, _
      ByVal clr As Color)
    For Each ctrl As Control In Page.Controls
        If TypeOf ctrl Is TextBox Then
            CType(ctrl, TextBox).BackColor = clr
        Else
            If ctrl.Controls.Count > 0 Then
                SetTextBoxBackColor(ctrl, clr)
            End If
        End If
    Next
End Sub
This would set each TextBox on the Page to a certain color. You can adapt this to search for and do whatever it is you are doing.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top