I have a strange issue that the last selected node in a PreRender event (which is displayed as the seletced node) is not the selected node on postback
I have a TreeView control on an AJAX page. Tree nodes are populated in code via the Expand() event [when a node is originally loaded, if it has child nodes, an empty dummy node is added to force the "+" to show. Expanding the node loads the real children].
Assume a tree is fully expanded, and there is a node in there with three child (leaf nodes). Select the bottom node of these. A user then clicks a "Move Up" button which updates the database (based on the selected tree node). On success, the moving nodes
parent is collapsed, then expanded.
This correctly loads the updated node list, and I store the value of the node to select (the one just moved). I use the nodes Value to search the tree for the node, and do not rely on node references since refreshed nodes are in effect, deleted.
In the Pre-Render event, I use the saved value to select the node just moved - this is the last thing that happens. I search for the node in the tree by value, and once found, call the "Select()" method.
When the tree is rendered in the browser, the changes are correct, the node 3 has moved to position 2, and node 2 displays the selected state. Clicking the "Move Up" button again, moves up the third node to position2, not node 2 (the selected node) to position
1. On Page load, the selected node is now node 3, and not node 2 (indicated as selected in the tree)
I've tried setting the selected node to false (no node selected in tree), clearing the child nodes manually - but always this issue
I've saved the value of the node selected in the pre-render, then on subsequent page load, selected the previously selected node, which works OK. Since node selection in code does not fire the treeview selected event, this is OK, if clunky
sbyard
Contributor
5891 Points
1196 Posts
Treeview Selection different on postback
Nov 09, 2007 12:14 PM|LINK
I have a strange issue that the last selected node in a PreRender event (which is displayed as the seletced node) is not the selected node on postback
I have a TreeView control on an AJAX page. Tree nodes are populated in code via the Expand() event [when a node is originally loaded, if it has child nodes, an empty dummy node is added to force the "+" to show. Expanding the node loads the real children].
Assume a tree is fully expanded, and there is a node in there with three child (leaf nodes). Select the bottom node of these. A user then clicks a "Move Up" button which updates the database (based on the selected tree node). On success, the moving nodes parent is collapsed, then expanded.
This correctly loads the updated node list, and I store the value of the node to select (the one just moved). I use the nodes Value to search the tree for the node, and do not rely on node references since refreshed nodes are in effect, deleted.
In the Pre-Render event, I use the saved value to select the node just moved - this is the last thing that happens. I search for the node in the tree by value, and once found, call the "Select()" method.
When the tree is rendered in the browser, the changes are correct, the node 3 has moved to position 2, and node 2 displays the selected state. Clicking the "Move Up" button again, moves up the third node to position2, not node 2 (the selected node) to position 1. On Page load, the selected node is now node 3, and not node 2 (indicated as selected in the tree)
I've tried setting the selected node to false (no node selected in tree), clearing the child nodes manually - but always this issue
Any ideas?
sbyard
Contributor
5891 Points
1196 Posts
Re: Treeview Selection different on postback
Nov 09, 2007 12:39 PM|LINK
Workround
I've saved the value of the node selected in the pre-render, then on subsequent page load, selected the previously selected node, which works OK. Since node selection in code does not fire the treeview selected event, this is OK, if clunky