|
-
May 22nd, 2002, 10:51 AM
#1
For each
Can I do a for each textbox on a form loop? I want to loop through all the textboxes on a form and change the background color if they are null.
Thanks!
-
May 22nd, 2002, 12:11 PM
#2
You cannot do it directly, but you can enumerate each control on a form, check for the type to see if it's a textbox and do your stuff
Code:
Dim ctl As Control
For Each ctl In Me.Controls
If TypeOf ctl Is TextBox Then
If ctl.Text = "" Then
ctl.BackColor = Drawing.Color.Red
Else
ctl.BackColor = Drawing.Color.White
End If
End If
Next
-
May 22nd, 2002, 01:18 PM
#3
For Each
I'm getting these errors:
error BC30456: 'Text' is not a member of 'System.Web.UI.Control'.
error BC30456: 'BackColor' is not a member of 'System.Web.UI.Control'.
error BC30456: 'BackColor' is not a member of 'System.Web.UI.Control'.
Can you help? Thanks!
-
May 22nd, 2002, 04:45 PM
#4
My guess is that you are not building a a windows application, but a web application. The code I gave you works with forms, but appearantly not with web controls.
If you are building a web application, I'm affraid I can't help you.
If you are not building a web application, try to find out why you are using webcontrols on your form, and try changing the the line with the TypeOf keyword to:
Code:
If TypeOf ctl Is System.Windows.Forms.TextBox Then
Good luck
-
October 9th, 2005, 10:31 AM
#5
Re: For each
Ok i know this is a pretty old post but this is the solution i just found. Not very nice and clean but it does work!
Dim obj As Control
Dim obj2 As HtmlForm
Dim obj3 As Object
For Each obj In Me.Page.Controls
If TypeOf obj Is HtmlForm Then
For Each obj3 In obj.Controls
If TypeOf obj3 Is WebControls.TextBox Then
' Do what ever here!
End If
Next
End If
Next
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|