Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

FindControl()  method and NamingContainer

Posted on 2007-04-04
4
Medium Priority
?
616 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 2000 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

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
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…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

609 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