This is a migrated thread and some comments may be shown as answers.

Find TreeView in another user control

4 Answers 83 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Joe
Top achievements
Rank 2
Joe asked on 25 Jan 2008, 04:33 PM
Hi,
This is killing me and I know it's probably just a general .net question, but I was hoping someone here could help out...

I am dynamically loading two user controls into a page.
treeview.ascx - contains a treeview with id "rtv"
editor.ascx - contains rad editor

I'm loading the user controls like this from default.aspx.vb:
Dim ctrlPage As UserControl = LoadControl(ctrlPath & "page/treeview.ascx")
PlaceHolder0.Controls.Add(ctrlPage)

I would like to find "rtv" in treeview.ascx from the code behind of editor.ascx so that I can enurate through the nodes.

Make sense?

Thanks for any help,
Joe

4 Answers, 1 is accepted

Sort by
0
Erjan Gavalji
Telerik team
answered on 25 Jan 2008, 04:50 PM
Hi Joe Hakooz,

To accomplish this you should have strictly defined base page and user control classes in the App_Code folder that will be inherited by the specific user controls and the page. The class for the treeview holder user control can expose the RadTreeview reference by a property and the editor holder user control will get a reference to it by casting its Page property to the exact page type.

Having the page constructed this way is not recommended, as the controls become too tightly coupled. Would you instead consider creating a third user control that will have a reference to both the user controls and will control them?

Kind regards,
Erjan Gavalji
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Joe
Top achievements
Rank 2
answered on 25 Jan 2008, 05:03 PM
"Would you instead consider creating a third user control that will have a reference to both the user controls and will control them?"

Absolutely...

Let's see if I have this straight. Create a new user control, which loads the other user controls. Then default.aspx would load only the new control.

But in the codebehind of the new control, how would I reference my treeview in treeview.ascx?
Dim treeview As RadTreeView = Me.FindControl("rtv")

Thanks again
0
Simon
Telerik team
answered on 28 Jan 2008, 04:18 PM
Hello Joe Hakooz,

Please, find attached a sample project illustrating the 'third control' approach discussed above.

I hope this helps.

Regards,
Simeon
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Joe
Top achievements
Rank 2
answered on 28 Jan 2008, 06:20 PM
Thanks Simeon,
This is very helpful!

Joe
Tags
TreeView
Asked by
Joe
Top achievements
Rank 2
Answers by
Erjan Gavalji
Telerik team
Joe
Top achievements
Rank 2
Simon
Telerik team
Share this question
or