Looping thru all controls on a WebForm

C

Craig G

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
 
O

Ollie Riches

each aspx page (System.Web.UI.Page) has a Controls collection, you can
iterate through this collection to acces the top most controls on a page,
don't forget that certain controls can contain 'child' controls so you will
have to iterate through these controls as well to access all the controls on
a page. You will also have to cast the control to specified type.

e.g. something like

foreach(System.Web.UI.Control control in Page.Controls)
{
if(control is System.Web.UI.Control.TextBox)
{
}
......
}


--
HTH

Ollie Riches
http://www.phoneanalyser.net

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a programmer
helping programmers.
 
C

Craig G

Cheers guys!!

i was using Parent.Controls instead of Page.Controls hence where i was going
wrong
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top