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

easier way to collect controls on a page?

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
"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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.