473,395 Members | 1,622 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,395 software developers and data experts.

Find Control

I am trying to figure out what the difference is between these 2
commands and which I should be using...what the difference is...

I placed this tag on my form...
<div id="fred" runat="server"></div>

I wrote these 2 statements to find the control....

HtmlGenericControl cntrl = (HtmlGenericControl) Page.Controls
[1].FindControl(CntrlName);

HtmlGenericControl cntrl2 = (HtmlGenericControl) Page.FindControl
(CntrlName);
Both apparently work and populate cntrl and cntrl2 with something.

I know (or believe) the first one looks at a particular "instance" of
controls, but I would have no idea as to what to set the index to for
him to begin his search. Does not seem to care if I put 1 or 0 as far
as the indexer goes. Why would this be?


Nov 18 '05 #1
2 7569
the current page is a control in Controls collection, in your sample case
index 1, thats why the FindControl works the same. index )

-- bruce (sqlwork.com)
"Jim Heavey" <JH*****@nospam.com> wrote in message
news:Xn*************************@207.46.248.16...
I am trying to figure out what the difference is between these 2
commands and which I should be using...what the difference is...

I placed this tag on my form...
<div id="fred" runat="server"></div>

I wrote these 2 statements to find the control....

HtmlGenericControl cntrl = (HtmlGenericControl) Page.Controls
[1].FindControl(CntrlName);

HtmlGenericControl cntrl2 = (HtmlGenericControl) Page.FindControl
(CntrlName);
Both apparently work and populate cntrl and cntrl2 with something.

I know (or believe) the first one looks at a particular "instance" of
controls, but I would have no idea as to what to set the index to for
him to begin his search. Does not seem to care if I put 1 or 0 as far
as the indexer goes. Why would this be?

Nov 18 '05 #2
Hi Jim,

The first thing you need to understand is that the FindControl() method only
looks at the immediate children of a Control, not children nested inside
other Controls under a Control. The second thing is that most likely your
Control is inside your WebForm (the "form runat=server" Control in the
Page), which means that it is at least inside that Control, and not the Page
that contains the WebForm. If it is inside another Control in the WebForm,
you would have to locate it in THAT Control's Controls Collection.

If you know which Control in the Page is the immediate parent, it's a
relatively simple matter to find it. If you are unsure, you can always
create a recursive function that searches throuigh the entire Page's
hierarchy of Controls to find the one you're looking for.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"Jim Heavey" <JH*****@nospam.com> wrote in message
news:Xn*************************@207.46.248.16...
I am trying to figure out what the difference is between these 2
commands and which I should be using...what the difference is...

I placed this tag on my form...
<div id="fred" runat="server"></div>

I wrote these 2 statements to find the control....

HtmlGenericControl cntrl = (HtmlGenericControl) Page.Controls
[1].FindControl(CntrlName);

HtmlGenericControl cntrl2 = (HtmlGenericControl) Page.FindControl
(CntrlName);
Both apparently work and populate cntrl and cntrl2 with something.

I know (or believe) the first one looks at a particular "instance" of
controls, but I would have no idea as to what to set the index to for
him to begin his search. Does not seem to care if I put 1 or 0 as far
as the indexer goes. Why would this be?

Nov 18 '05 #3

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

Similar topics

8
by: Yasutaka Ito | last post by:
Hi, Is there a way to find to which control the current control is docked against? For example, let's say I have panel1 and panel2 docked to left within a form. The panel1 is the first one on...
1
by: bill yeager | last post by:
I have a datagrid control within a datalist control. When I try and do a "Find" on the control, the object comes back with nothing and then my pgm crashes. I am 100% sure that my datagird inside...
2
by: TM | last post by:
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...
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,...
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...
1
by: Salim | last post by:
Hi, I'm trying to get UniqueID of a linkbutton. I have 2 web user controls. And a master page. In fisrst web user control there is a datalist. In datalist ItemCreated event, I try to find...
5
by: gnewsgroup | last post by:
In my user control, I would like to find a Label control in the parent page (the page that uses my user control). I need to update that Label.Text when something happens in the user control. I...
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...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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,...
0
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...

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.