Solved

FindControl()  method and NamingContainer

Posted on 2007-04-04
4
584 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
  • 2
4 Comments
 
LVL 17

Expert Comment

by:lem2802
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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 video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now