• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 626
  • Last Modified:

FindControl() method and NamingContainer

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
pmartin8
Asked:
pmartin8
  • 2
1 Solution
 
Elvio Lujan.Net Senior DeveloperCommented:
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
 
mirmansoorCommented:
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
 
pmartin8Author Commented:
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
 
mirmansoorCommented:
anytime... you're most welcome... :)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now