treeview in page inherited from template has err on click

D

DOK

I've built a web page template .vb that contains a treeview built in code-behind. The code works when I copy it into a test .aspx page. My problem is that when I use the template .vb by inheriting it into an .aspx page, the treeview appears correctly but raises an error on the second click event. The treeview appears, and I click on an expandable node, and it expands, but the treeview doesn't respond to any further clicks, and I get an error in the lower left corner of IE about an object reference not being set. I believe that the error is in the javascript that is automatically generated for the control

I have pasted the VB code below. But before I show you that, is this a correct approach? This treeview is the left nav for the Website's page template. Click events on the parent nodes just expand them. Click events on the child nodes have URLs to open other pages using the template. I wonder if I should make the treeview be a separate user control .ascx or custom control called in the template instead? Or some other approach?

Thank you VERY much for helping me with this!!

Private Sub LoadNav(
Dim tnHome As New TreeNode(
Dim tnClients As New TreeNode(
Dim tnEditProject As New TreeNode(
Dim tnEquipment As New TreeNode(
Dim tnHome As New TreeNode(
Dim tnInvoices As New TreeNode(
Dim tnNewProject As New TreeNode(
Dim tnProject As New TreeNode(
Dim tnPurchase As New TreeNode(
Dim tnReports As New TreeNode(

'Treeview has 3 hierarchical levels. Some nodes have children & some don't
'Some are both parent & child. Only create a TreeNode obj if it has child(ren)
' Parent
' Child
' Child
' Parent
' Child
' Parent&Child
' Child
' Child

'Set treeview properties
With tvwNa
.EnableViewState = Tru
.AutoPostBack = Tru
.SelectExpands = Tru
With .DefaultStyl
.Add("font-size", "x-small"
.Add("font-family", "Tahoma"
.Add("color", "#006699"
.Add("background-color", "#ffffff"
.Add("padding", "1px"
End Wit

With .HoverStyl
.Add("color", "#006699"
.Add("font-weight", "600"
.Add("background-color", "gold"
End Wit

With .SelectedStyl
.Add("color", "#006699"
.Add("font-weight", "600"
.Add("background-color", "gold"
End Wit
End Wit

'Build the treeview, populating it with pages that can be called
AddParentNode(tnHome, "Home", "PrototypeHTMLOnly.aspx"

AddParentNode(tnHome, "Home", ""
AddChildNode("Company Documents", "CompanyDocs.aspx", tnHome

AddParentNode(tnEquipment, "Equipment", "", tnHome
AddChildNode("Equipment1", "Equipment1.aspx", tnEquipment
AddChildNode("Equipment2", "Equipment2.aspx", tnEquipment
AddChildNode("Equipment3", "Equipment3.aspx", tnEquipment
AddChildNode("Equipment4", "Equipment4.aspx", tnEquipment
AddChildNode("Equipment5", "Equipment5.aspx", tnEquipment
AddChildNode("Equipment6", "Equipment6.aspx", tnEquipment

AddChildNode("Web Application", "ApplicationDisplay.aspx", tnHome

AddParentNode(tnPurchase, "Purchase", "", tnHome
AddChildNode("Purchase1", "Purchase1.aspx", tnPurchase
AddChildNode("Purchase2", "Purchase2.aspx", tnPurchase
AddChildNode("Purchase3", "Purchase3.aspx", tnPurchase
AddChildNode("Purchase4", "Purchase4.aspx", tnPurchase
AddChildNode("Purchase5", "Purchase5.aspx", tnPurchase
AddChildNode("Purchase6", "Purchase6.aspx", tnPurchase
AddChildNode("Purchase7", "Purchase7.aspx", tnPurchase

AddChildNode("Change Password", "ChangePassword.aspx", tnHome

‘……quite a few more parents & children omitted here

'Add the treeview to the placeholder
plcLeftNav.Controls.Add(tvwNav

End Su

Private Sub AddParentNode(ByRef tn As TreeNode,
ByVal strText As String,
ByVal strUrl As String, _
Optional ByRef tnParent As TreeNode = Nothing)

With tn
.ID = strText
.Text = strText
.NavigateUrl = strUrl
End With

'If a parent node was passed, add this child node to it.
If Not tnParent Is Nothing Then
tnParent.Nodes.Add(tn)
'If no parent node was passed, it's a child of the root.
Else
tvwNav.Nodes.Add(tn)
End If

End Sub

Private Sub AddChildNode(ByVal strText As String, _
ByVal strUrl As String, _
ByRef tnParent As TreeNode)

Dim tn As New TreeNode()

With tn
.ID = strText
.Text = strText
.NavigateUrl = strUrl
End With

tnParent.Nodes.Add(tn)

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top