?
Solved

FindControl()  method and NamingContainer

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

771 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