[2005] trying to loop through text boxes
for some reason my code won't recognize text boxes on my webform?
Code:
Dim myControl As Control
For Each myControl In Page.Controls
If myControl.GetType Is GetType(System.Web.UI.WebControls.TextBox) Then
CType(myControl, TextBox).Text = String.Empty
End If
Next myControl
Re: [2005] trying to loop through text boxes
Your boxes are probably not direct descendants of the Page object.
You need to write a recursive function that calls itself each time on all controls as it finds them, so that all controls get analyzed.
Be warned; your code is going to be slow. This is not the way to be clearing out boxes usually. Even though it means more work to you as the programmer, you should manually create an array with the Controls as each member of the array and then loop the array.
Re: [2005] trying to loop through text boxes
Are you sure they're textboxes, or HTMLTEXTBOXes?
Re: [2005] trying to loop through text boxes
For a start Texas that will slow your page down immensely.
I'm not sure it's the best way but I usually create a Sub called ClearTextBoxes() which I call and clears all the boxes. That way it can be called from anywhere and if I add any textboxes in the future I only have to add the .Clear() code in that Sub :thumb: