473,791 Members | 3,360 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

FindControl() method and NamingContainer

Dan
Hi,

I created a custom control (ParentCustomCo ntrol) 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
(ChildCustomCon trol) which is using a custom template too.

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

(this.FindContr ol("MyButton") as ImageButton)

I can also access the ChildCustomCont rol
(this.FindContr ol("ChildCustom Control1") as ChildCustomCont rol)) 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 ChildCustomCont rol
are innaccessible.. .

Anyone can help ?

Thanks !

Apr 4 '07 #1
1 3394
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

ChildCustomCont rol ctrl = this.FindContro l("ChildCustomC ontrol1") as
ChildCustomCont rol;
TextBox txt = ctrl.FindContro l("whatever") as TextBox;

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

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

I created a custom control (ParentCustomCo ntrol) 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
(ChildCustomCon trol) which is using a custom template too.

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

(this.FindContr ol("MyButton") as ImageButton)

I can also access the ChildCustomCont rol
(this.FindContr ol("ChildCustom Control1") as ChildCustomCont rol)) 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 ChildCustomCont rol
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
5709
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 my page. It appears that I am unable to use avariable as the parameter for the method as I get the followingerror message: "Object reference not set to an instance of an object" CODE: Panel pnl = (Panel) FindControl(testvariable);...
1
7783
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 regularly. Has anyone seen this before? It's pretty aggravating to have to iterate through the controls in each grid cell to find the ones I need, especially since finding those cells is not always easy. Here's my ItemDataBound() handler: private void...
3
1389
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 something still? Do I really have to use the Web controls in order to be able to change properties on the control? I'm trying to create a user control and have the apsx page include that control, but change a few properties, like the Table Border...
6
1637
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 textbox name and then pass it to the FindControl() method to return the value. This works great when I use the method in the code-behind for the exact page that I want to use it on. However, I'd like to use this same method on other pages throughout my...
2
6566
by: christof | last post by:
How to do it: My page: <asp:DataList ID="dataListRoleMembers" ...> .... <FooterTemplate> <asp:LinkButton ID="btnAddMember" runat="server" OnClick="btnAddMember_Click">Add...</asp:LinkButton> <asp:TextBox ID="txtAddMember" runat="server"></asp:TextBox>
2
3480
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 control... Let's say the control I want to find is "myControl". So I call e.theObject.FindControl("myControl"); It always returns null and I know the name of the control is good (that's the ID I gave it, is it possible it has changed because it's...
0
1058
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 standard, column index 3, ID="ddlTestStandardID"). So for the first dropdown control, I have: OnSelectedIndexChanged="OnDDLTypeModified" Private Sub OnDDLTypeModified(ByVal sender As Object, ByVal e As System.EventArgs) Dim ddl As...
14
3205
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 within my Default.aspx as follows: MyUC C = (MyUC)this.FindControl("SomeID"); When I try to run this, I get error: "The type or namespace name 'MyUC' could not be found (are you missing a
5
2544
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 td.FindControl('id') it returns null? any ideas off the top why this may be?
0
9669
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
9517
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10428
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
10207
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...
0
9997
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9030
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...
0
6776
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();...
0
5435
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4110
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.