looping through controls collection

A

astro

I am not farmilar with the object model for webforms.

I want to loop through the web form controls - pulling out the checkboxes on
the form like the following:

For Each ctrl In Me.Controls

If TypeOf ctrl Is CheckBox Then

'do something here.....

End If

Next

This works fine with windows forms of course...

But completely misses the dozen web checkboxes I have on my web form. Is
there an alternative syntax for web forms? Please note that I am not
refering to html checkboxes but the web control checkboxes.



thanks.
 
A

astro

The control hierchy is:

form
---> html grid layout panel
-------->> html table
---------->>> webctrl checkbox

The loop has 3 iterations, one having the form1 as an ID, the other two
having no ID at all. I even placed additional webctrl checkboxes on the
form itself - and they were not found in the controls collection....

I've played around with this a bit and if I place the checkboxes in a
webctrl panel I can successfully iterate via the panel1.controls
collection... so this is what I am going to do....
 
M

Marina Levit [MVP]

Right, this would be the same in windows forms. If you had your checkboxes
nested in a panel or some other container control,you would have to use the
same technique in windows forms.

I am not sure why you say that the checkboxes were not found even when
placed on the form itself, I've never had that problem. Perhaps you thought
they were directly on the form, but they were really inside some other
control.
 
A

astro

what is the parent container of the checkboxes here? what would the syntax
be?
In vb.net the 'me' pronoun is a quick way of getting to the form - which is
usually the container..using recursion I can drill down any subcontainer and
get it's controls. How would I implement a similar strategy for webforms?

Thanks.

(thanks for the feedback Marina btw)
 
M

Marina Levit [MVP]

I don't know - whatever you put on there. I am just saying maybe you didn't
realize you were putting the checkboxes in there.

What you describe it exactly how it works with web forms. Which is exactly
how it works with windows forms. You say Me.Controls, and then loop
through it, and use recursion to loop through the controls of each control,
etc.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top