473,322 Members | 1,736 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

easier way to collect controls on a page?

My goal is to collect all the textboxes on a given page in code (or all
checkboxes).

The only way that I know how is traversing through the hierarchy and collect
them

Page
|__Controls
|____HtmlForm
|__text boxes found here

The trouble is controls are embedded in others such as user controls, panel,
table, datagrid, etc, in which case, I'd have to look in there to find them
and there is no way I can write code to cover every possible hierarchy and
chase them down. Is there a cleaner way of doing this? I suppose I can
write a recursive function to do this.

If on a given web form, I want to collect all textboxes. As simple as that,
but hierarchies can be pretty complex.
Nov 18 '05 #1
3 1028
Jos
"David" <sp************@spammersgohome.com> wrote in message
news:4F*******************@twister.socal.rr.com...
My goal is to collect all the textboxes on a given page in code (or all
checkboxes).

The only way that I know how is traversing through the hierarchy and collect them

Page
|__Controls
|____HtmlForm
|__text boxes found here

The trouble is controls are embedded in others such as user controls, panel, table, datagrid, etc, in which case, I'd have to look in there to find them and there is no way I can write code to cover every possible hierarchy and
chase them down. Is there a cleaner way of doing this? I suppose I can
write a recursive function to do this.

If on a given web form, I want to collect all textboxes. As simple as that, but hierarchies can be pretty complex.


A recursive function is the way to go (VB.NET):

Sub DoControls(ctl As Control)
If(TypeOf ctl Is TextBox) Then
' do your stuff here
End If
Dim myControl As Control
For Each myControl In ctl.Controls
DoControls(myControl)
Next
End Sub

--

Jos
Nov 18 '05 #2
"David" <sp************@spammersgohome.com> wrote in message
news:4F*******************@twister.socal.rr.com...
My goal is to collect all the textboxes on a given page in code (or all
checkboxes).

The only way that I know how is traversing through the hierarchy and collect them

Page
|__Controls
|____HtmlForm
|__text boxes found here

The trouble is controls are embedded in others such as user controls, panel, table, datagrid, etc, in which case, I'd have to look in there to find them and there is no way I can write code to cover every possible hierarchy and
chase them down. Is there a cleaner way of doing this? I suppose I can
write a recursive function to do this.

If on a given web form, I want to collect all textboxes. As simple as that, but hierarchies can be pretty complex.


What happens in the future when you change one of the TextBox controls into
a RichTextBox control or some other control?

One awkward way to do this would be to store references to all of the
controls in an array at runtime:

Dim ca As New Control(){txtBox1, txtBox2, rtxBox3}

--
John Saunders
johnwsaundersiii at hotmail
Nov 18 '05 #3
Check out this article, this will help you,
http://www.extremeexperts.com/Net/Ar...hControls.aspx

--
Saravana
Microsoft MVP - ASP.NET
www.extremeexperts.com

"David" <sp************@spammersgohome.com> wrote in message
news:4F*******************@twister.socal.rr.com...
My goal is to collect all the textboxes on a given page in code (or all
checkboxes).

The only way that I know how is traversing through the hierarchy and collect them

Page
|__Controls
|____HtmlForm
|__text boxes found here

The trouble is controls are embedded in others such as user controls, panel, table, datagrid, etc, in which case, I'd have to look in there to find them and there is no way I can write code to cover every possible hierarchy and
chase them down. Is there a cleaner way of doing this? I suppose I can
write a recursive function to do this.

If on a given web form, I want to collect all textboxes. As simple as that, but hierarchies can be pretty complex.

Nov 18 '05 #4

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

Similar topics

0
by: Michael | last post by:
Hi All, I am working on my intranet reporting web site, by use of IIS5 + Office2000 +SQL2000. Currently, the first step, I show user an ASP web-interface to collect user input, keyword...
2
by: james | last post by:
If I have a user control with some control on it like a TextBox's and buttons does calling the default Dispose on my user control cause those inner controls to also be disposed ? Or must I do my...
9
by: Frank Rizzo | last post by:
I understand the basic premise: when the object is out of scope or has been set to null (given that there are no funky finalizers), executing GC.Collect will clean up your resources. So I have...
11
by: Antonio | last post by:
Hello, here is what I am doing. 1) user accesses web page and clicks button to build report 2) web page accesses web service whose data type is DataSet (public DataSet methodname()...) 3) web...
5
by: Mrinal Kamboj | last post by:
Hi , Any pointers when it's absolute necessary to use it . Does it has a blocking effect on the code , as GC per se is undeterministic . what if GC.collect is followed in next line by...
13
by: dm1608 | last post by:
I know all the hype right now from Microsoft is how much easier, faster, and less code ASP.NET 2.0 provides over previous versions. I'm puzzled by this as I could turn out an classic ASP webpage...
3
by: Mikegtr | last post by:
I need to collect and send data from a rs232 device- it is a simple temperature controller. I need to be able to collect actual temperature ,store the result in database (mysql) and show it in...
4
by: svgeorge | last post by:
I NEED TO COLLECT FROM THE GRIDVIEW(DATASELECTED) IN TO A TABLE(SelectedPayment) -------------------------------------------------------------------------------- How TO COLLECT THE ROWS...
0
by: johnspruit | last post by:
I have a method to collect all the controls on a form, also the controls in containers on the form. It seems that some controls, like NumericUpDown also have child controls. I only want controls...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.