473,387 Members | 1,882 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Find controls ?

TM
What is the method used to find all asp.net server controls (run at server)
such as TextBox, ListBox, CheckBox... currently defined on an Asp.Net page
at run time. I need it inside of a controlled loop (for int i=...).

Reason: I need to fill up an updatable dataset with all fields entered on
the asp.net page instead of manually going 1 field at a time and hard code
the control name (i.e. TextBoxFirstName.Text=something and so on)

Thanks for your help.

Tom
Nov 18 '05 #1
2 1813
You may be going to more trouble than necessary. Every System.Web.UI.Control
has a Controls Collection, made up of all the System.Web.UI.Controls that
are immediately contained within that Control. Note that this is NOT all the
Controls that are contained within that Control, but only IMMEDIATELY
contained. If, for example, you have a Control that contains another Control
inside a Control, only the top-level Control belongs to the Controls
Collection of the containing Control The one uder it belongs to ITs Controls
Collection.

Let's say, for example, that you loop through the Control Collection of a
Control, such as a WebForm. You may be able to get hold of an instance of
that Control, but how do you know WHICH Control it is? Different Controls
are treated differently. You would have to use some mechanism (such as
Reflection) to determine what kind of Control it is, cast it as that Type,
find out which Control it is, and what its value is. That is a lot more
resource usage (and work for you) than just identifying the Control and
getting something out of it, as in your example:

someString = TextBoxFirstName.Text;

There ARE situations in which this sort of thing is useful. If, for example,
you have a situation in which you don't know what or how many Controls are
going to be used, using Reflection would be one of the ONLY ways of handling
it.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

"TM" <Th**************@Yahoo.Com> wrote in message
news:eq*************@TK2MSFTNGP11.phx.gbl...
What is the method used to find all asp.net server controls (run at server) such as TextBox, ListBox, CheckBox... currently defined on an Asp.Net page
at run time. I need it inside of a controlled loop (for int i=...).

Reason: I need to fill up an updatable dataset with all fields entered on
the asp.net page instead of manually going 1 field at a time and hard code
the control name (i.e. TextBoxFirstName.Text=something and so on)

Thanks for your help.

Tom

Nov 18 '05 #2
I use for example a HTML grid layout panel and change the property (right
mouse click) to "run as server control". In your code you get a
System.Web.UI.HtmlControls.HtmlGenericControl.

Then you can use the Control property.

Example:
System.Web.UI.HtmlControls.HtmlGenericControl myGrid;
for(int 1=0; i<myGrid.Controls.Count; i++) {
... //look at myGrid.Controls[i].
}

"TM" wrote:
What is the method used to find all asp.net server controls (run at server)
such as TextBox, ListBox, CheckBox... currently defined on an Asp.Net page
at run time. I need it inside of a controlled loop (for int i=...).

Reason: I need to fill up an updatable dataset with all fields entered on
the asp.net page instead of manually going 1 field at a time and hard code
the control name (i.e. TextBoxFirstName.Text=something and so on)

Thanks for your help.

Tom

Nov 18 '05 #3

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

Similar topics

2
by: Michael | last post by:
Need some help trying to read values from web controls - specifically *finding* the controls (like a drop down list) - that are added dynamically added within an asp:panel control. The page...
6
by: TomislaW | last post by:
How to find all user controls (ascx) loaded on a Page?
9
by: tshad | last post by:
How do I find (and set) a couple of labels in the Footer after a DataGrid is filled? I have a bunch of DataGrids that get displayed nested inside a DataList. The datagrid looks like: ...
10
by: Sacha Korell | last post by:
I'm trying to load a drop-down list with all DropDownList control names from another page. How would I be able to find those DropDownList controls? The FindControl method will only find a...
5
by: sck10 | last post by:
Hello, I am using the code below to set the values of a DetailsView template field using FindControl. My question is how would you find a control if its a Boundfield control? For example,...
2
by: madani | last post by:
Hi, I made custom web control. this control have an Event like "TestEvent", How can I find out if properties of other controls of parent Page is changed inside this event when I fire that event...
13
by: usenet | last post by:
How and where can one find out about the basics of VB/Access2003 syntax? I am a died in the wool C/C++/Java Linux/Unix programmer and I am finding it difficult to understand the program format...
6
by: DC | last post by:
Hi, our cms (asp.net 2.0) dynamically inserts controls into asp.net pages, sometimes 50 and more per page, and if we run into a performance bottleneck we have a hard time finding out which...
7
by: =?Utf-8?B?V2ViQnVpbGRlcjQ1MQ==?= | last post by:
i have a master page and aseries of controls labeled fn1, fn2, fn3 , ... i want ot loop and use find control but i'm finding them. i'm using the following w/o luck ContentPlaceHolder cph =...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...

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.