SelectedNode wrong when SelectedNodeChanged event fires

B

biker

Looking back, I guess my first request was a bit long and confusing...I hope
this works out better.

I have a treeview on a master page that, when I click on a leaf node, fires
the SelectedNodeChanged event. Only problem is, the treeview.SelectedNode
points to the wrong node within the event code.

Can anyone help?? Please??
 
K

Keith Patrick

Is it pointing to the old selection, the new one, or a completely different
one altogether?
 
B

biker

A different one. No matter where in the tree I click, it goes to the first
sibling node of the node I click on. If I have
A
a
b
c
B
d
e
f

and click on any of a, b or c, it goes to a...if I click on any of d, e or
f, it goes to d.
 
K

Keith Patrick

I want to say that I've run into this problem before when I was customizing
a tree control (I did one that displays usercontrols as nodes...quite the
pain, lemme tell you). By any chance are you using a custom control? If
not, could you post some of the markup so I can try to reproduce?
 
B

biker

No, no usercontrols in the treeview. Here is an extract from my code...maybe
you can see what is happening, I've been staring at it for too long:

TREEVIEW PLACED IN A TABLE CELL ON THE MASTER PAGE:

<asp:TreeView ID="tvMenu" runat="server" DataSourceID="Menu"
ShowExpandCollapse="False" NodeIndent="8">
<ParentNodeStyle Font-Bold="True" />
<HoverNodeStyle Font-Italic="True" />
<RootNodeStyle Font-Bold="True" />
<NodeStyle ForeColor="Firebrick" HorizontalPadding="3px" />
<DataBindings>
<asp:TreeNodeBinding DataMember="PACS" SelectAction="None" />
<asp:TreeNodeBinding DataMember="ANode"
ImageUrl="~/Public/bullet-red.gif" SelectAction="None" TextField="Name"
ValueField="Permit" />
<asp:TreeNodeBinding DataMember="BNode"
ImageUrl="~/Public/bullet-red.gif" SelectAction="None" TextField="Name"
ValueField="Permit" />
<asp:TreeNodeBinding DataMember="CNode"
ImageUrl="~/Public/bullet-narrow-red.gif" TextField="Name"
ValueField="Permit" TargetField="Target" />
</DataBindings>
</asp:TreeView>
<asp:XmlDataSource ID="Menu" runat="server"
DataFile="~/Menu.xml"></asp:XmlDataSource>



CODE-BEHIND FILE FOR MASTER PAGE:

Partial Class PACSMasterPage
Inherits System.Web.UI.MasterPage

Private appsess As PACS.AppSession

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
appsess = New PACS.AppSession(Session)
End Sub

Protected Sub tvMenu_DataBound(ByVal sender As Object, ByVal e As
System.EventArgs) Handles tvMenu.DataBound
tvMenu_Traverse(tvMenu.Nodes(0))
End Sub

Protected Sub tvMenu_Traverse(ByVal node As TreeNode)
For Each n As TreeNode In node.ChildNodes
If n.ChildNodes.Count > 0 Then
tvMenu_Traverse(n)
If n.Value <> "ALL" Then
If Not Validate_User(n.Value, appsess.USER_ACCESS_CSV)
Then
n.Collapse()
End If
End If
End If
Next
End Sub

Protected Function Validate_User(ByVal permit As String, ByVal access As
String) As Boolean
For Each a As String In Split(access, ",")
For Each p As String In Split(permit, ",")
If p = "ALL" Then Return True
If a = p Then Return True
Next
Next
Return False
End Function

Protected Sub lnkLogOff_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles lnkLogOff.Click
Dim j As Common.JavaScript = New Common.JavaScript()
j.WindowClose()
j.Send(MyBase.Page)
End Sub

Protected Sub tvMenu_SelectedNodeChanged(ByVal sender As Object, ByVal e
As System.EventArgs) Handles tvMenu.SelectedNodeChanged
If Validate_User(tvMenu.SelectedNode.Value, appsess.USER_ACCESS_CSV)
Then
If tvMenu.SelectedNode.Target <> String.Empty Then
Response.Redirect(tvMenu.SelectedNode.Target)
End If
End Sub
End Class




XML FILE FOR TREEVIEW DATASOURCE

<?xml version="1.0" standalone="yes"?>
<PACS Name="PACS Menu" Permit="ALL">
<ANode Name="Data Interface" Permit="ALL">
<BNode Name="Data Logger" Permit="ALL">
<CNode Name="New Entry" Permit="ALL"
Target="/PACS/App_Forms/DataInt/DataLogger_new.aspx" />
<CNode Name="Edit Existing Entry" Permit="ALL"
Target="/PACS/App_Forms/DataInt/DataLogger_select.aspx" />
</BNode>
<CNode Name="Log Inspection Results" Permit="ALL" Target="" />
<CNode Name="View Inspection Results" Permit="ALL" Target="" />
</ANode>
<ANode Name="Reports" Permit="ALL">
<BNode Name="PACS Standard Reports" Permit="ALL">
<CNode Name="Assembly Defect Summary" Permit="ALL"
Target="/PACS/App_Forms/Rpts/reports.aspx?type=100" />
<CNode Name="Traceability" Permit="ALL"
Target="/PACS/App_Forms/Rpts/reports.aspx?type=900" />
<CNode Name="Data Screening" Permit="ALL"
Target="/PACS/App_Forms/Rpts/reports.aspx?type=910" />
<CNode Name="Data Screening Detail" Permit="ALL"
Target="/PACS/App_Forms/Rpts/reports.aspx?type=920" />
<CNode Name="Part Project Detail" Permit="ALL"
Target="/PACS/App_Forms/Rpts/reports.aspx?type=930" />
</BNode>
</ANode>
<ANode Name="Maintenance Functions" Permit="ALL">
<CNode Name="Parts / Assemblies" Permit="ALL"
Target="/PACS/App_Forms/Maint/products.aspx" />
<CNode Name="Projects" Permit="ALL" Target="" />
<CNode Name="Attribute Groups" Permit="ALL"
Target="/PACS/App_Forms/Maint/Quality.aspx" />
<CNode Name="Defect Rate Groups" Permit="ALL" Target="" />
</ANode>
<ANode Name="Administration" Permit="ADMIN">
<BNode Name="Maintain Users" Permit="ADMIN">
<CNode Name="Create New User" Permit="ADMIN"
Target="/PACS/App_Forms/Admin/user_new.aspx" />
<CNode Name="Update Existing User" Permit="ADMIN"
Target="/PACS/App_Forms/Admin/user_update.aspx" />
</BNode>
<CNode Name="Purge Test Data" Permit="ALL" Target="" />
<CNode Name="Purge Unit Test Data" Permit="ALL" Target="" />
<CNode Name="Shift Times" Permit="ALL" Target="" />
</ANode>
</PACS>
 
S

stacy

Hi biker,

I wish I had some words of wisdom as I am experiencing the exact same
problem. Have you found a solution or workaround?

Thanks,
Stacy
 
S

stacy

Hi again,

I have found, with a great deal of help from a coworker with more
experience in Web development, a way to make my code work. We simply
set the Value property of each node to the ChildNodes.Count value as
the tree is recursively built. My tree is built programmatically. For
the example tree you gave, the value field should be set as follows:

A (value = "0")
a (value = "0")
b (value = "1")
c (value = "2")
B (value = "1")
d (value = "0")
e (value = "1")
f (value = "2")

We also noted, that at PageLoad, the SelectedNode property of the tree
is correct, but with the value properties set, the SelectedNode
property is correct in the SelectedNodeChanged event also.

I hope this imformation helps you,
Stacy
 
B

biker

I put the Permit value in my XML in the Value field. Sadly, this does not
influence the outcome. Perhaps the fact you are manually loading the tree
whereas I am linking the treeview to the XML through a datasource...but I
think that is another of the things I tried. Maybe I'll give that another
shot to make sure.

Thanks for the suggestion; I'm glad you found a solution for your situation.
 
R

ReyN

you have your treenodebindings with SelectAction set to NONE, which in
effect raises no events when a node is selected.

if you need to use the SelectedNodeChanged event when a node is
selected, then SelectAction must be set to either Select or SelectExpand
 
B

biker

Actually, when I reset things to the way they were when I was testing, I
forgot to set the SelectAction to Select. That's the value I used during my
testing. The event was triggering, but the SelectedNode value was pointing
to the wrong node. Events were definately firing, and I had breakpoints in
the code to check the values.
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top