469,325 Members | 1,555 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,325 developers. It's quick & easy.

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,
Craig

Nov 19 '05 #1
5 1580
http://www.code101.com/Code101/Displ...le.aspx?cid=83

http://www.ragingsmurf.com/code.aspx?key=CP05DWVM3F

"Craig G" <craig.gamble@y_arrasoftware.com> wrote in message
news:uO**************@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


Nov 19 '05 #2
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
--------------------------------

Nov 19 '05 #3
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


Nov 19 '05 #4
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:uO**************@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

Nov 19 '05 #5
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:uO**************@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

Nov 19 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Hai Nguyen | last post: by
1 post views Thread by Charles A. Lackman | last post: by
4 posts views Thread by Poppy | last post: by
1 post views Thread by Jim in Arizona | last post: by
2 posts views Thread by pob | last post: by
1 post views Thread by tshad | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by Gurmeet2796 | last post: by
reply views Thread by mdpf | last post: by
reply views Thread by harlem98 | last post: by
reply views Thread by listenups61195 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.