473,756 Members | 1,810 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Iterating through controls (VB)

I have been trying to iterate through the controls on my form and preset all
textboxes to a cssClass. Unfortunately, I have been unable to figure out
how to recursively move through sub-controls and all of my textboxes are in
asp panels. The code I have can see the panels but not what is in them.

Help please.

Current code:
Dim frm As Control

Dim ctrl As Control

frm = FindControl("Fo rm2")

For Each ctrl In frm.Controls

If TypeOf ctrl Is TextBox Then

CType(ctrl, TextBox).CssCla ss = cssTextbox

End If

Next

Nov 17 '05 #1
1 3215
You basically have to call your function on each of the controls in the
Controls collection of the current control. When you get to a control with
no children - then it's not a container control, and you can check if it's a
textbox, etc.

"Jeremy" <ww*****@comcas t.net> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
I have been trying to iterate through the controls on my form and preset all textboxes to a cssClass. Unfortunately, I have been unable to figure out
how to recursively move through sub-controls and all of my textboxes are in asp panels. The code I have can see the panels but not what is in them.

Help please.

Current code:
Dim frm As Control

Dim ctrl As Control

frm = FindControl("Fo rm2")

For Each ctrl In frm.Controls

If TypeOf ctrl Is TextBox Then

CType(ctrl, TextBox).CssCla ss = cssTextbox

End If

Next

Nov 17 '05 #2

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

Similar topics

4
23826
by: Adam Parkin | last post by:
Hi all, what I want to do is write a function to toggle the enabled field of all controls within a frame, but what I can't figure out is how does one iterate through all controls in a frame object? For example, if I wanted to iterate through all controls in a form, I'd write something like: Dim x For Each x In frmMyForm.Controls x.Enabled = Not x.Enabled
3
22466
by: Cy Huckaba | last post by:
I have been looking around for a sample on how to read an XSD schema and iterate through the elements to display them. I am working in VB.Net and I have looked at all of the docs on msdn and can find plenty of samples on how to read it in and then write it write back out...with no manipulation or analysis before writing. I load the XMLSchema object but can't get into the right collection of objects to get back any valid items. I was...
2
1944
by: rcoutts | last post by:
I have a table with no ID field. I would like to read a single field of each record using DLookup or something similar and pass it to a VB function that's already been written. However, DLookup doesn't seem to be able to "index" a table, but rather returns a field based on some matching criteria. What's the simplest way to iterate a table like I need to do in VB? My VB skills are mediocre and my SQL skills are even worse, so if it's...
6
1296
by: Dany P. Wu | last post by:
Hi everyone, I created a page which contains a two-column table. The first column has a bunch of labels, and the second a bunch of textboxes. Here's the code: ====================================================== Protected WithEvents Container As System.Web.UI.WebControls.PlaceHolder Private Sub ConstructEditTable() Container.Controls.Add(New LiteralControl("<table>" & vbNewLine))
4
1685
by: Milsnips | last post by:
hi there, i have a strange problem. I want to programatically loop through each control on a page, but am having issues. my test example: 1. header.ascx - the ascx control finds all the child controls no problems 2. default.aspx - i dont find any controls that are placed directly on the
4
1694
by: John Buchmann | last post by:
I thought this would not be difficult, but i'm stumped! I need to iterate through a bunch of form fields, and read the data (value, text, etc.) from them. (I need to iterate through them programmatically because it is not known ahead of time which form fields will be displayed on the browser. The fields will be displayed or hidden depending on what the user just clicked.)
4
4427
by: Ali | last post by:
I used to clear my page's control in Visual Studio 2003 using code like this: Dim c As Control For Each c In Page.Controls(1).Controls If TypeOf c Is TextBox Then CType(c, TextBox).Text = Nothing End If If TypeOf c Is DropDownList Then CType(c, DropDownList).SelectedIndex = 0 End If Next
2
2568
by: Bill44077 | last post by:
Hi, I am trying to iterate though the controls on a content page that has a master page so I can disable text. If it weren't on a content page it is simple: foreach (Control c in Page.Controls) { if (c is TextBox) {
5
3857
by: Dave H | last post by:
I was doing this in a .Net 1.1 site, but it doesn't work in 2.0, because the objects aren't public (I think) For k = 1 To iDDLCount ddlObject = CallByName(oParent, sDDLName & k, CallType.Get) ddlObject.Items.Clear() Next Any ideas?
0
9431
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
9255
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
9844
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9689
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
8688
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
5119
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
5289
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3780
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2647
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.