Solved

FindControl()  method and NamingContainer

Posted on 2007-04-04
4
592 Views
Last Modified: 2013-11-07
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 !
0
Comment
Question by:pmartin8
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 18

Expert Comment

by:Elvio Lujan
ID: 18851245
you can public the controls with properties

        Public Property txt1() As TextBox
            Get
                Return localTXTBOX
            End Get
            Set(ByVal value As TextBox)
                localTXTBOX = value
            End Set
        End Property
0
 
LVL 5

Accepted Solution

by:
mirmansoor earned 500 total points
ID: 18851278
take the child control in an object like this. (i'm not sure abt the syntax)
Dim childCtrl = (this.FindControl("ChildCustomControl1") as ChildCustomControl)) ;
then
childCtrl.FindControl("childOfChildControlsID") // this might work...
0
 
LVL 1

Author Comment

by:pmartin8
ID: 18851906
Thank you !

I only had to modify this line
    childCtrl.FindControl("childOfChildControlsID")
by this one
    childCtrl.ControlTemplateContainer.FindControl("childOfChildControlsID")

And it works !!
Thanks again !
0
 
LVL 5

Expert Comment

by:mirmansoor
ID: 18854315
anytime... you're most welcome... :)
0

Featured Post

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

724 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question