Friday, March 16, 2012

Looping thru all controls on a WebForm

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,
Craighttp://www.code101.com/Code101/Disp...cle.aspx?cid=83
http://www.ragingsmurf.com/code.aspx?key=CP05DWVM3F
"Craig G" <craig.gamble@.y_arrasoftware.com> wrote in message
news:uOM5dwOGFHA.1932@.TK2MSFTNGP14.phx.gbl...
> 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
>
>
Hi Craig:
One approach:
http://odetocode.com/Articles/71.aspx
HTH,
Scott
http://www.OdeToCode.com/blogs/scott/
On Tue, 22 Feb 2005 14:35:34 -0000, "Craig G"
<craig.gamble@.y_arrasoftware.com> wrote:

>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
>
Hi Craig,
All controls are stored in the Controls property of the Page
control.
for each current as Control in Page.Controls
' do whatever you want to
next
Hope that helps.
Cheers,
Gaurav Vaish
http://www.mastergaurav.org
http://mastergaurav.blogspot.com
--
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.
"Craig G" <craig.gamble@.y_arrasoftware.com> wrote in message
news:uOM5dwOGFHA.1932@.TK2MSFTNGP14.phx.gbl...
> 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
>
>
Cheers guys!!
i was using Parent.Controls instead of Page.Controls hence where i was going
wrong
"Craig G" <craig.gamble@.y_arrasoftware.com> wrote in message
news:uOM5dwOGFHA.1932@.TK2MSFTNGP14.phx.gbl...
> 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
>
>

0 comments:

Post a Comment