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

FindControl() method and NamingContainer

Dan
Hi,

I created a custom control (ParentCustomControl) which is using a
custom template (implementing ITemplate interface), in the
instantiateIn method of this template I create all the controls I need
(Label, textboxes, button) and I also create another custom control
(ChildCustomControl) which is using a custom template too.

My problem comes when I'm trying to access the child Controls of
ChildCustomControl with the FindControl method. I can access every
others controls with a call like this :

(this.FindControl("MyButton") as ImageButton)

I can also access the ChildCustomControl
(this.FindControl("ChildCustomControl1") as ChildCustomControl)) but
his childs are not accessible... I always get a null reference error,
I think it's could be related to the NamingContainer, because only the
controls created in the the InstantiateIn method of ChildCustomControl
are innaccessible...

Anyone can help ?

Thanks !

Apr 4 '07 #1
1 3360
Dan,

Due to performance reasons FindControl method does not perform recursive
search, which means if you want to find a control within instantiated
template, you have to call FindControl of the container. In your case you
first obtain Child

ChildCustomControl ctrl = this.FindControl("ChildCustomControl1") as
ChildCustomControl;
TextBox txt = ctrl.FindControl("whatever") as TextBox;

Also, make sure all the controls are created and template instantiated in
CreateChildControls(), and call EnsureChildControls always before refreing
control contained in the template.

Hope this helps
--
Milosz
"Dan" wrote:
Hi,

I created a custom control (ParentCustomControl) which is using a
custom template (implementing ITemplate interface), in the
instantiateIn method of this template I create all the controls I need
(Label, textboxes, button) and I also create another custom control
(ChildCustomControl) which is using a custom template too.

My problem comes when I'm trying to access the child Controls of
ChildCustomControl with the FindControl method. I can access every
others controls with a call like this :

(this.FindControl("MyButton") as ImageButton)

I can also access the ChildCustomControl
(this.FindControl("ChildCustomControl1") as ChildCustomControl)) but
his childs are not accessible... I always get a null reference error,
I think it's could be related to the NamingContainer, because only the
controls created in the the InstantiateIn method of ChildCustomControl
are innaccessible...

Anyone can help ?

Thanks !

Apr 4 '07 #2

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

Similar topics

2
by: Mark D'Souza via .NET 247 | last post by:
In trying to create a Panel object with the FindControl methodusing a string variable as the paramater. The code is below. The variable 'testvariable' is equal to pnl_0 which is anexisting Panel on...
1
by: James G. Beldock | last post by:
I have seen the following behavior: when issuing a Page.FindControl() for a control which exists in an item template (from within an ItemDataBound() event, for example), I get nulls back...
3
by: Andrea Williams | last post by:
Ok, thanks to a kind person yesterday, I've started using the FindControl() method. Although I able to get this to work for Web Controls, I'm unable to find the HTML Controls? Am I missing...
6
by: D Sheldon | last post by:
I have created a method that accepts a string value (representing the name of a textbox) and then returns the value. Because the name of the textbox can change, I first build a string with the...
2
by: christof | last post by:
How to do it: My page: <asp:DataList ID="dataListRoleMembers" ...> .... <FooterTemplate> <asp:LinkButton ID="btnAddMember" runat="server"...
2
by: ThunderMusic | last post by:
Hi, I have a custom WebControl. I fire an event and send, as the EventArg, another WebControl that contains sub controls (ParseChildren(true))... It can contain anything, but I want to find one...
0
by: jyuan | last post by:
Hi, I have two dropdownlist template columns in datagrid. Once the first one (Test Type, in column index 2, ID="ddlTestTypeID") selection changed, I need to re-bound the second dropdownlist (test...
14
by: =?Utf-8?B?QWxleCBNYWdoZW4=?= | last post by:
Hi. I have created a UserControl ("MyUC"). I've put a bunch of instances of that control on a Page ("Defaul.aspx"). The control works fine. Now, I want to be able to use "FindControl()" from...
5
by: =?Utf-8?B?cm9kY2hhcg==?= | last post by:
hey all, i've added a dropdownlist object into tableCell td in my code further down the code i inspect the td.Controls and i can see the the dropdownlist bright as day. however, when i try to do...
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
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?
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
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...
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...
0
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...
0
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,...

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.