Looping thru all controls on a WebForm

  • Thread starter Thread starter Craig G
  • Start date Start date
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
 
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.
 
Cheers guys!!

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