我们希望从不同的网页操作位于母版页中的ASP.Net TreeView。
此编码来自Master Page网络表单代码隐藏文件。我们想在另一个网页的代码隐藏文件的Page_Load事件中复制此编码。当我尝试在其他网络表单中使用此编码时,
objTreeView = Knowledge_Academy1.loginView.FindControl("TreeViewMain")
我们收到一个错误,指出loginView受到保护。我们如何取消保护它以便我可以复制相同的编码?
以下是来自主Web表格代码隐藏文件的工作编码:
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
答案 0 :(得分:1)
我建议查看这篇MSDN文章:http://msdn.microsoft.com/en-us/library/xxwa0ff0(VS.80).aspx
例如:
Dim mpTreeview As Treeview
mpTreeview = CType(Master.FindControl("TreeViewMain"), Treeview)