Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

loop through each textbox on page

Tags:

asp.net

vb.net

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?

like image 923
thegunner Avatar asked Nov 22 '25 02:11

thegunner


1 Answers

Try this

For Each control As Object In form1.Controls
        If TypeOf control Is TextBox Then
            control.Text = ""
        End If

    Next
like image 103
Nikolaj Zander Avatar answered Nov 24 '25 17:11

Nikolaj Zander



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!