Reputation: 3
So I am trying to loop through the controls on my page and disable all of the textboxes. I found solutions that recommend doing it this way
For Each ctrl As Control in Me.Controls
If TypeOf ctrl Is TextBox Then
ctrl.Enabled = False
End If
Next
However, when i attempt to do this, Enabled is not available to modify because ctrl is not of type TextBox. I then tried converting it via CType, but it did not affect any of the textboxes on the page. Any help would be great thanks!
Upvotes: 0
Views: 519
Reputation: 1205
try something like this:
For Each ctrl As WebControl In Me.Controls
If TypeOf ctrl Is TextBox Then
DirectCast(ctrl, TextBox).Enabled = False
End If
Next
(you may be missing its declaration)
Upvotes: -1