473,573 Members | 3,876 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 1738
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
5346
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 ...
7
16350
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
1194
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...
4
1297
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
1783
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
1398
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
16065
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...
1
1539
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
5120
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...
0
7789
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...
0
7707
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8037
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8086
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5605
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...
0
5296
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...
0
3737
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...
0
3743
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2227
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.