By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,681 Members | 1,335 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,681 IT Pros & Developers. It's quick & easy.

Looping through controls

P: n/a
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.
Nov 20 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
"Poppy" <pa**********@NOSPAMthemedialounge.com> wrote in message
news:ua**************@TK2MSFTNGP11.phx.gbl...
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

Nov 20 '05 #2

P: n/a
Cheers
"Jeremy Cowles" <jeremy.cowles[nosp@m]asifl.com> wrote in message
news:92*******************@twister.tampabay.rr.com ...
"Poppy" <pa**********@NOSPAMthemedialounge.com> wrote in message
news:ua**************@TK2MSFTNGP11.phx.gbl...
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

Nov 20 '05 #3

P: n/a
Cor
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
Nov 20 '05 #4

P: n/a
* "Poppy" <pa**********@NOSPAMthemedialounge.com> scripsit:
How can I loop through controls on a form and find out what type they are.


For Windows Forms:

<http://www.mvps.org/dotnet/dotnet/samples/controls/downloads/EnumerateControls.zip>

--
Herfried K. Wagner
MVP VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.