473,804 Members | 3,228 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Object with all of form's controls to loop through ASP.NET

Is there a way I can loop through a form object in ASP.NET codebehind like
in VB.NET and get all of the controls?
Nov 18 '05 #1
4 1809
Use the Controls collection.

dim ctrl as Control
for each ctrl in Page.Controls
.....
next

"David A. Beck" <da****@beckb.c om> wrote in message
news:uY******** ******@TK2MSFTN GP10.phx.gbl...
Is there a way I can loop through a form object in ASP.NET codebehind like
in VB.NET and get all of the controls?

Nov 18 '05 #2
You can loop through the controls collection.
However it gets complicated if you have controls nested within other
container controls.
Here's some code Kevin Spencer posted a while back that provides a good
demonstration using recursion.

Private Function FindChildContro l(ByVal objSearchContro l As
System.Web.UI.C ontrol, _
ByVal strControlID As String) As Object

Dim objChildControl As System.Web.UI.C ontrol
Dim objControl As System.Web.UI.C ontrol

If objSearchContro l.Controls.Coun t = 0 Return Nothing

For Each objChildControl in objSearchContro l.Controls
objControl = FindChildContro l(objChildContr ol, strControlID)
If Not IsNothing(objCo ntrol) Return objControl
Next

Return Nothing
End Function

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
Hire top-notch developers at http://www.able-consulting.com

"David A. Beck" <da****@beckb.c om> wrote in message
news:uY******** ******@TK2MSFTN GP10.phx.gbl...
Is there a way I can loop through a form object in ASP.NET codebehind like
in VB.NET and get all of the controls?

Nov 18 '05 #3
Steve:

Thanks. This code searches for a given control name in a control that itself
has controls. I have not been sucessful yet in adapting it to loop through
the Page.Controls object for my "Form1" to get all the controls.

Dab
"Steve C. Orr [MVP, MCSD]" <St***@Orr.ne t> wrote in message
news:e0******** ******@TK2MSFTN GP10.phx.gbl...
You can loop through the controls collection.
However it gets complicated if you have controls nested within other
container controls.
Here's some code Kevin Spencer posted a while back that provides a good
demonstration using recursion.

Private Function FindChildContro l(ByVal objSearchContro l As
System.Web.UI.C ontrol, _
ByVal strControlID As String) As Object

Dim objChildControl As System.Web.UI.C ontrol
Dim objControl As System.Web.UI.C ontrol

If objSearchContro l.Controls.Coun t = 0 Return Nothing

For Each objChildControl in objSearchContro l.Controls
objControl = FindChildContro l(objChildContr ol, strControlID)
If Not IsNothing(objCo ntrol) Return objControl
Next

Return Nothing
End Function

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
Hire top-notch developers at http://www.able-consulting.com

"David A. Beck" <da****@beckb.c om> wrote in message
news:uY******** ******@TK2MSFTN GP10.phx.gbl...
Is there a way I can loop through a form object in ASP.NET codebehind like in VB.NET and get all of the controls?


Nov 18 '05 #4
Check out this article,
http://www.extremeexperts.com/Net/Ar...hControls.aspx

--
Saravana
Microsoft MVP - ASP.NET
www.extremeexperts.com

"David A. Beck" <da****@beckb.c om> wrote in message
news:ex******** ******@TK2MSFTN GP12.phx.gbl...
Steve:

Thanks. This code searches for a given control name in a control that itself has controls. I have not been sucessful yet in adapting it to loop through the Page.Controls object for my "Form1" to get all the controls.

Dab
"Steve C. Orr [MVP, MCSD]" <St***@Orr.ne t> wrote in message
news:e0******** ******@TK2MSFTN GP10.phx.gbl...
You can loop through the controls collection.
However it gets complicated if you have controls nested within other
container controls.
Here's some code Kevin Spencer posted a while back that provides a good
demonstration using recursion.

Private Function FindChildContro l(ByVal objSearchContro l As
System.Web.UI.C ontrol, _
ByVal strControlID As String) As Object

Dim objChildControl As System.Web.UI.C ontrol
Dim objControl As System.Web.UI.C ontrol

If objSearchContro l.Controls.Coun t = 0 Return Nothing

For Each objChildControl in objSearchContro l.Controls
objControl = FindChildContro l(objChildContr ol, strControlID)
If Not IsNothing(objCo ntrol) Return objControl
Next

Return Nothing
End Function

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
Hire top-notch developers at http://www.able-consulting.com

"David A. Beck" <da****@beckb.c om> wrote in message
news:uY******** ******@TK2MSFTN GP10.phx.gbl...
Is there a way I can loop through a form object in ASP.NET codebehind like in VB.NET and get all of the controls?



Nov 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
3366
by: deko | last post by:
I'm hoping someone can sanity check my understanding of the Object Model for Forms/Controls. I'm having trouble drilling down into Control properties. First, I have a record set with the following for a given Form: 1)Container
4
3474
by: Ryan Liu | last post by:
How to loop though controls on the form? I set each control's TabStop and TabIndex, but at run time, I press Tab key, it jump though first control to last control and does not go back to the first one unless I use Alt + Tab to go reverse direction. How can I write C# code to allow user just to use Tab kek to loop though the controls? Thanks!
3
3517
by: Bill | last post by:
I have a seating chart web form that has over 50 entry field controls (tables/booths) where I use a DropDownList box to select a single company name from a single large list of organizations (200 plus conference attendees). All web form datavalues will be one of the same 200 organizations in this list. I would like to avoid creating 50 separate exact copies of the same DataSet object. Can you help? Q. Exactly how do I use the same...
1
2316
by: Angus Lepper | last post by:
I'm writing a stock ticker for a stock market simulation, and can load the data into the xmlreader in the first place, but can't figure out how to refresh/update the data in it. Any ideas? Code: Public Class Form1 Inherits System.Windows.Forms.Form
5
6468
by: Varangian | last post by:
ImageButton ship; ship = new ImageButton; for (int i=0; i<5; i++) { ship.ImageUrl = pathofImage; ship.ID = "ShipNo" + i.ToString(); ship.Click += new ImageClickEventHandler(this.ImageBtn_Click); this.Form1.Controls.Add(ship); }
1
3660
by: Miguel Ribeiro | last post by:
Hi, The crux of my problem is that I want to destroy an object without using the reference (by using a collection etc.) and have the reference basically show 'nothing' I have a MDI form with forms that are going to be displayed on it. The layout is quite complex since I am going to try get the same functionality as Outlook. What I need to know is this:
6
1621
by: Kevin | last post by:
I come up with these questions during the day, do some research, and then look for experienced users' input. 1. In Access, we already know it's pretty much an automatic save if you enter data. How can I prevent that? How can I make an effective way in Access to not commit a change until a 'Save' button is pressed, and also to backout changes using a 'Cancel' button? 2. Let's say I have 15 objects on a form, and they're locked. I have...
35
2631
by: Jamey Shuemaker | last post by:
I've seen multiple threads (several in the last 6 months or so) on this topic, but I wanted to clarify my practices. I understand the need for cleaning object variables by setting them to Nothing and/or closing them, but I'm not sure about the order. As I understand it all object variables that I create like: Set rs = SomeExistingRecordset need to be cleaned up via:
3
1912
by: Shawn | last post by:
I'm trying to go through a large number of logically named textboxes using a loop and cannot figure out how short of explicitly referencing every single one.
0
9708
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
10589
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10340
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...
1
10327
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9161
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
7625
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
6857
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();...
1
4302
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
2
3828
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.