Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) _
Handles Button1.Click
EmptyTextBoxValues(Me)
End Sub
Private Sub EmptyTextBoxValues(ByVal parent As Control)
For Each c As Control In parent.Controls
If (c.Controls.Count > 0) Then
EmptyTextBoxValues(c)
Else
If TypeOf c Is TextBox Then
CType(c, TextBox).Text = ""
End If
End If
Next
End Sub
This sub is for to clear all textboxes value, i just need to know how did it work ??
The
EmptyTextBoxValuessub recursively calls all child controls (if they exists) – if non exist, it checks if they are a text box and if so, clears it.To start – it loops through every child control belonging to the passed in control:
It then tests whether the child control has any child controls of its own, and if so, calls itself with the child control:
If no such child controls exist on the child control, a test is made whether the type of the control is of
TextBoxand if so, it is cleared: