473,986 Members | 1,376 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1753
http://www.code101.com/Code101/Displ...le.aspx?cid=83

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

"Craig G" <craig.gamble@y _arrasoftware.c om> wrote in message
news:uO******** ******@TK2MSFTN GP14.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.c om> 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.C ontrol.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.c om> wrote in message
news:uO******** ******@TK2MSFTN GP14.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.c om> wrote in message
news:uO******** ******@TK2MSFTN GP14.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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
5370
by: Simon | last post by:
I've got a webform and many controls on it. I would like to iterate thru the control collection to get all the textboxes control to let me change the text property. Here is my code...for unknown reason, this loop iterates only 3 times! Help please! Thanks! Dim Control As Web.UI.Control Dim TextBox As System.Web.UI.WebControls.TextBox For Each Control In Controls If TypeOf (Control) Is System.Web.UI.WebControls.TextBox Then
7
16378
by: Hai Nguyen | last post by:
I have another question. I'm trying to loop through all the textboxes on a web application. The snippet is below //foreach(WebControl ctr in Page.Controls) foreach(Control ctr in Page.Controls) { if(ctr is TextBox) { TextBox t = (TextBox)ctr; t.BackColor = Color.AliceBlue;
1
1210
by: Charles A. Lackman | last post by:
Hello, I have created a User Control within Visual Studio and it contains a button that allows the user to querry a database. I dynamically add additional controls to the page based on the number of rows retured inside a dataset. All works well, but I have noticed that the control is rendered after the WebForm's load event is fired. This creates duplicate controls in certain situations. I have been able to prevent this from happening...
4
1316
by: Nick | last post by:
Hi - I'm trying to loop through the textboxes on a page to unlock them for editing. The Enabled property is set to false, and the following code is on an 'Edit' button on the form. Can anyone tell me why it doesn't work? Thanks Nick. Code:
4
1798
by: Poppy | last post by:
How can I loop through controls on a form and find out what type they are. I want to loop through controls on a webform and if they are visible textboxes change there value if NULL to "na". Also If I placed this code in a module or class how would the code know which page I was refering to.
1
1428
by: Jim in Arizona | last post by:
Using VB .. Is there a way to loop through all drop down lists on a web form checking for a specific value (ddlDropDown.SelectedValue) and then, based on that value, cause a specific label to go visible or not? Thanks, Jim
2
16125
by: pob | last post by:
Whats the difference between using a control or a listbox when looping thru a listbox. In example 1 it dims a listbox and an example 2 it dims a control. Please explain. Thanks in advance Example 1 from Allen Browne MVP Access To use a Multiselect list box for criteria for a report, you need to loop through its ItemsSelected collection to create a string that can act as the WhereCondition for your report.
1
1552
by: tshad | last post by:
I was trying to do this in Javascript but found I can't do spans (which is what Labels turn into). I can do a loop thru a control list something like: Public Sub LoopingControls(ByVal oControl As Control) Dim frmCtrl As Control oArrayList = New ArrayList
4
5156
by: sparks | last post by:
well I am trying to get around looking at all the buttons with a case statement so I was trying this. Public Sub looking(ctlname) Dim ctl As OptionGroup Dim btn As ToggleButton ctl = Me.Controls(ctlname) ============================= For Each btn In ctl.children <<<< I know that the children doesn't make since .its just a note to myself..this is where I am stumped.
0
10395
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11477
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10140
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8528
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7678
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6475
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6627
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4810
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3814
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.