473,986 Members | 1,277 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.
Nov 20 '05 #1
4 1797
"Poppy" <pa**********@N OSPAMthemedialo unge.com> wrote in message
news:ua******** ******@TK2MSFTN GP11.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.C ontrol
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.publi c.dotnet.framew ork.aspnet
HTH,
Jeremy

Nov 20 '05 #2
Cheers
"Jeremy Cowles" <jeremy.cowle s[nosp@m]asifl.com> wrote in message
news:92******** ***********@twi ster.tampabay.r r.com...
"Poppy" <pa**********@N OSPAMthemedialo unge.com> wrote in message
news:ua******** ******@TK2MSFTN GP11.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.C ontrol
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.publi c.dotnet.framew ork.aspnet
HTH,
Jeremy

Nov 20 '05 #3
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(B yVal sender As System.Object, ByVal e As
System.EventArg s) 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
* "Poppy" <pa**********@N OSPAMthemedialo unge.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/EnumerateContro ls.zip>

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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2589
by: Ivo | last post by:
Hi, I have an audio file (.mid or .wav or .mp3) in an object element: <object id="snd" classid="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf. cab#Version=5,1,52,701" type="application/x-oleobject" width="282" height="53"> <param name="FileName" value="Tjaikovsky_-_The_sorcerers_apprentice.mid" /> <param name="loop" value="true" /> <... more presentational params...
1
6454
by: Jozef | last post by:
Hello, I'm trying to loop through forms by doing a "For Each" in the Currentdb. I'm doing this like the following; Dim db as dao.database Dim docLoop as document Dim ctrl as control Set db = CurrentDb
16
7258
by: TD | last post by:
This is the code under a command button - Dim ctl As Control For Each ctl In Me.Controls If ctl.BackColor <> RGB(255, 255, 255) Then ctl.BackColor = RGB(255, 255, 255) End If Next ctl
2
4240
by: Shawn | last post by:
Hi. I'm trying to loop through all webcontrols in my System.Web.UI.HtmlControls.HtmlForm. This is my code: Dim form As HtmlForm Dim control As Control form = Me.FindControl("completion") For Each control In form.Controls ....
5
1753
by: Craig G | last post by:
how do i go about this thru serverside code (VB.NET)? any links to any articles anywhere? basically i just want something simple that will loop thru all txt & cbo server side controls, and then set there back color dependant on whether they are enabled or not Cheers, Craig
5
4017
by: johnb41 | last post by:
I need to loop through a bunch of textbox controls on my form. The order of the loop is very important. For example, the top one must be read first, then the one below it, etc. My first attempt was to put the controls in a Panel, and then loop through the controls collection of the panel. What happened is it read the controls from the bottom of my form to the top! So I tried a more manual process. I named each textbox like this:
7
5482
by: Ken | last post by:
Hi All - I have a filtered GridView. This GridView has a check box in the first column. This check box is used to identify specific rows for delete operations. On the button click event I loop through the filtered GridView to identify the selected rows and assemble some XML to be sent to a stored proc. The problem I have is that when looping through the GridView, it doesn't
6
6125
by: jobs | last post by:
This code was working, but then stopped working. I don't think I completely understand it. I pass it a formview name and it would loop through checking the value of textboxes. problem is now as i debug it, it's telling me there are only a count of 3 controls in that for loop. and they have clientid values like: ctl00_Content1_FormMaint_ctl03
0
2908
by: Rene Goris | last post by:
Hi all, I am trying to add meta:resourcekey's to database programmatically looping throug webcontrols, but i cann't read the 'meta:resourcekey' from the webcontrol. The 'meta:resourcekey' will not show up as attribute. How can i get the value of the 'meta:resourcekey' ? THE CODE: public string RetrieveControls(Control myControl){
0
10395
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10204
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11894
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
11667
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10969
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
10139
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6475
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6624
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4809
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.