0

We would like to manipulate an ASP.Net TreeView that's in a Master Page from a different web page.

This coding is from the Master Page web form code-behind file. We would like to duplicate this coding in a Page_Load event of another web page's code-behind file. When I try to use this coding in the other web form,

objTreeView = Knowledge_Academy1.loginView.FindControl("TreeViewMain")

we get an error that states loginView is protected. How do we unprotect it so I can duplicate the same coding?

Here is the working coding from the master web form code-behind file:

Public Class Knowledge_Academy1
    Inherits System.Web.UI.MasterPage

Protected Sub TreeViewMain_TreeNodeExpanded(sender As Object, e As TreeNodeEventArgs)

    Dim objTreeView As TreeView
    objTreeView = loginView.FindControl("TreeViewMain")

    Select Case e.Node.Text

        Case "Maintenance"

            ' Make sure all nodes except for Maintenance are collapsed.
            '----------------------------------------------------------
            For Each treenode As TreeNode In objTreeView.Nodes
                If treenode.Text = "Parents" Or
                    treenode.Text = "Students" Or
                    treenode.Text = "Financial" Then

                    treenode.Collapse()
                End If
            Next treenode

        Case "Students"

            ' Make sure all nodes except for Students are collapsed.
            '-------------------------------------------------------
            For Each treenode As TreeNode In objTreeView.Nodes
                If treenode.Text = "Parents" Or
                    treenode.Text = "Maintenance" Or
                    treenode.Text = "Financial" Then

                    treenode.Collapse()
                End If
            Next treenode

        Case "Parents"

            ' Make sure all nodes except for Parents are collapsed.
            '------------------------------------------------------
            For Each treenode As TreeNode In objTreeView.Nodes
                If treenode.Text = "Students" Or
                    treenode.Text = "Maintenance" Or
                    treenode.Text = "Financial" Then

                    treenode.Collapse()
                End If
            Next treenode

        Case "Financial"

            ' Make sure all nodes except for Financial are collapsed.
            '--------------------------------------------------------
            For Each treenode As TreeNode In objTreeView.Nodes
                If treenode.Text = "Parents" Or
                    treenode.Text = "Maintenance" Or
                    treenode.Text = "Students" Then

                    treenode.Collapse()
                End If
            Next treenode
        Case Else

    End Select
End Sub
tshepang
  • 12,111
  • 21
  • 91
  • 136
Emad-ud-deen
  • 4,734
  • 21
  • 87
  • 152

1 Answers1

1

I would suggest looking at this MSDN article: http://msdn.microsoft.com/en-us/library/xxwa0ff0(VS.80).aspx

So for example:

Dim mpTreeview As Treeview

mpTreeview = CType(Master.FindControl("TreeViewMain"), Treeview)
Ryan McDonough
  • 9,732
  • 3
  • 55
  • 76