How do I access a parent's property from a nested child user control?

Hi all.  I'm probably missing something obvious.  I have a UserControl inside a PlaceHolder which is inside a Panel.  That panel is a child control of the parent UserControl that contains the property I need to access. Using the code below, I get a casting error, obviously because my upload control's direct parent is the placeholder control. What is the best way for me to access the property I need

Should I just abandon trying to seek out the property in the parent above and just pass the values I need in custom event args? My parent control has an "upload files" button that exposes the visibility of the upload control's panel. I could probably pass what I need through event args, but I would still need to get a reference to that parent control though just so I could listen for the event. I'm just looking for the simplest solution.  

Just to recap:  My control heirarchy is:  Parent UserControl -> Panel -> PlaceHolder -> Upload UserControl and I need to get a reference to a property in the Parent contriol from the Upload Control.  Thanks for any help.
FileManager40 ucFileManager40 = (FileManager40)this.Parent;
			Category _currentFolder = ucFileManager40._CurrentFolder;

Open in new window

LVL 3
svcoderAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Alpesh PatelCommented:
here is the scenario for your requirement
i am using asp.net langugage so you can get logic and build your own

Declaration:


dim l_instanceUcParent as UserControls_UcParent            ' get one instatnce of your parent usercontrol UserControls_UCParent may be change according to your Parent usercontrol name

Dim l_instancePanel As  Panel

dim l_instanceUcUploadChild as UserControls_UcUploadChild          '' get one instatnce of your UploadChild usercontrol UserControls_UCUploadChild may be change according to your UploadChild usercontrol name


Code:

l_instanceUcParent = me.FindControl("HereWriteYourParentUserControlID")
l_panel= l_instanceUcParent.FindControl("HereWriteYourPanelIDgeretedforPanelofUCParent")
l_instanceUploadChild = l_panel.FindControl("HereWriteYourUploadChildUserControlID")

now you can access each and ever property  l_instanceUploadChild over here

thanx and regards
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Smacky311Commented:
How about something like this...


UserControl myParentUserControl = 
(UserControl)FileUpload1.Parent.Parent.Parent;
        
AttributeCollection myParentsAttributes = myParentUserControl.Attributes;

Open in new window

0
svcoderAuthor Commented:
I actually went with a different approach. Since this approach would couple the user control to the parent page, I had to take another approach. Instead of crawling up the control heirarchy, I simply created a public method within the user control and called that method when I load the control. I passed the objects I needed in the method call. That way the control could receive the required data and could still be re-usable in other pages. The solutions provided would probably work with some massaging to be able to crawl up the container controls to get to the parent, but I needed a different solution. Thanks for the replies.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.