how to reference a textbox

tracmonali

Member
Joined
Jul 16, 2008
Messages
6
Programming Experience
1-3
Hello:

On my web form I have several text boxes named from textbox1 to textbox30. How do I "reference" these text boxes in code behind "vb.net"? Say i wish to write a for loop.
for i = 1 to 30
textbox.text.length>0
stmt...
next i

How do I code this part?
 
That might not work with nested controls :

VB.NET:
Dim Ctl As Control
        Dim MyTextbox As TextBox
        For i As Integer = 1 To 30
            Ctl = Me.Controls.Item("Textbox" & i.ToString)
            If Ctl IsNot Nothing Then
                MyTextbox = CType(Ctl, TextBox)
                MyTextbox.Text = i.ToString
            End If
        Next
 
Back
Top