Find TreeView in another user control

5 posts, 0 answers
  1. Joe Hakooz
    Joe Hakooz avatar
    65 posts
    Member since:
    Dec 2007

    Posted 25 Jan 2008 Link to this post

    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
  2. Erjan Gavalji
    Admin
    Erjan Gavalji avatar
    1455 posts

    Posted 25 Jan 2008 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Joe Hakooz
    Joe Hakooz avatar
    65 posts
    Member since:
    Dec 2007

    Posted 25 Jan 2008 Link to this post

    "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
  5. Simon
    Admin
    Simon avatar
    2281 posts

    Posted 28 Jan 2008 Link to this post

    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
  6. Joe Hakooz
    Joe Hakooz avatar
    65 posts
    Member since:
    Dec 2007

    Posted 28 Jan 2008 Link to this post

    Thanks Simeon,
    This is very helpful!

    Joe
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017