I want to loop through each textbox on a web form and clear any text within the control..
I've tried:
Dim ctrl As TextBox
For Each ctrl In form1.Controls
ctrl.Text = ""
Next
but I amm getting an error message:
Unable to cast object of type 'System.Web.UI.LiteralControl' to type 'System.Web.UI.WebControls.TextBox'.
Any ideas?
Try this
For Each control As Object In form1.Controls
If TypeOf control Is TextBox Then
control.Text = ""
End If
Next
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With