|
-
Oct 10th, 2003, 07:51 AM
#1
Thread Starter
Fanatic Member
Looping through controls
How can I loop through controls on a form and find out what type they are.
I want to loop through controls on a webform and if they are visible textboxes change there value if NULL to "na".
Also
If I placed this code in a module or class how would the code know which page I was refering to.
-
Oct 10th, 2003, 08:37 AM
#2
Frenzied Member
just a quick sample...this is in C#.
VB Code:
foreach(x in base.Controls)
if(x is Textbox)
{
//do something
}
Being educated does not make you intelligent.
Need a weekend getaway??? Come Visit
-
Oct 10th, 2003, 09:04 AM
#3
Thread Starter
Fanatic Member
The problem Im having is that I cant get to the text property of the control so I can change it.
-
Oct 10th, 2003, 03:37 PM
#4
yay gay
Originally posted by Memnoch1207
just a quick sample...this is in C#.
VB Code:
foreach(x in base.Controls)
if(x is Textbox)
{
//do something
}
actually ur code is wrong as the base class will not have any control in it
you have to loop thru all class controls..do it the following way:
VB Code:
public sub SetTextBoxes(ByRef WebPage pageRef)
for each ctrl as Control in pageRef.Controls)
'code (sorry i dont have vb.net here so i can say but try
'if (ctrl.gettype() = typeof("TextBox"))
'(CType(ctrl, TextBox)).Text = "na"
next
end function
anyways as i am no vb.net developer i might have some sintax errors
Last edited by PT Exorcist; Oct 10th, 2003 at 03:40 PM.
\m/  \m/
-
Oct 10th, 2003, 11:18 PM
#5
Addicted Member
Well, I'm not sure if this is what you need, but it might help a little.
VB Code:
Dim ctrl As Control
For Each ctrl In Me.Controls
If TypeOf ctrl Is TextBox Then
If ctrl.visible = True Then
If ctrl.Text = Nothing Then
ctrl.text = "na"
End If
End If
End If
Next
Take my love
Take my land
Take me where I cannot stand
I don't care, I'm still free
You can't take the sky from me...
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
|