Looping through controls

  • Thread starter Thread starter Poppy
  • Start date Start date
P

Poppy

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.
 
Poppy said:
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.

This is a VB Lanugage group, not WebForms/ASP. In VB, you could do it like
this:

Dim c as Windows.Forms.Control
For Each c In Me.Controls
If TypeOf c Is TextBox Then
'// Do something
End If
Next


But I'm sure that doesn't help you much, I would try asking your question in
the ASP.NET group:

microsoft.public.dotnet.framework.aspnet


HTH,
Jeremy
 
Cheers


Jeremy Cowles said:
This is a VB Lanugage group, not WebForms/ASP. In VB, you could do it like
this:

Dim c as Windows.Forms.Control
For Each c In Me.Controls
If TypeOf c Is TextBox Then
'// Do something
End If
Next


But I'm sure that doesn't help you much, I would try asking your question in
the ASP.NET group:

microsoft.public.dotnet.framework.aspnet


HTH,
Jeremy
 
Hi Poppy,

I wish the "typeof" did work on a webform, but as far as I know it does
not.
That makes it almost impossible to use a for each loop with sence on a
webform.
\\\
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim ctr As Control
For Each ctr In Me.Controls
If TypeOf ctr Is TextBox Then
ctr.Visible = False
End If
Next
End Sub
///
Does nothing .
\\\
Dim ctr As Control
For Each ctr In Me.Controls
ctr.Visible = False
next
///
This works but I never could come at the text property therefore I need a
cast to textbox.

(There is no error message, you can only see it by trying this, both code is
full accepted)

Very much
;-((((
Cor
 
Back
Top