Hello, I have an application with a MasterPage. On this MasterPage, I have an UltraWebTree used for navigation. The navigation part works fine, but the tree goes back to its original state upon each post. i.e. I have node 1 with sub nodes A, B, C, and node 2 with sub nodes X, Y, Z. If I collapse node 2 (X, Y, and Z collapse and are not visible), and then click A, when the A page comes up, node 2 is expanded. How do I make the tree maintain state between posts?
Hello!
Check if you aren't repopulating your webtree on each postback.
Bye,
Carlos Marcão (Altitude Software, Portugal)
OK, I checked whether I am repopulating the tree. I'm not. When I'm on a page and "use" the menu it is in this state when I click one of the links in the tree.
MenuX SubMenu1 SubMenu2MenuY SubMenu1 SubMenu2
After clicking link on the tree, it looks thusly
MenuXMenuY
Can I not have this behavior without going to Frames?
Yes, the solution to the master/detail page scenario (navigation tree maintains state between pages) requires some minor javascript work:
First, on the master page (DefaultMaster.master) set a reference mapping the tree menu id to a global variable, using the following javascript code added in the head section:
//tree section, treeMenuId is global variable referenced in every content page to expand the menu var treeMenuId = null; function UltraWebTree_Menu_InitializeTree(treeId) { treeMenuId = treeId; }
Also, include the following line to the control's markup to call the function above:
<ClientSideEvents InitializeTree="UltraWebTree_Menu_InitializeTree" />
Then, on each detail page, add the following javascript code to expand the corresponding parent node on the menu:
function pageLoad() { ExpandMenu(treeMenuId); }
//expand page's parent node in the tree menu var expandedFlag; function ExpandMenu(treeId) { if (!expandedFlag) { igtree_getTreeById(treeId).getNodes()[0].setExpanded(true); //admin menu expandedFlag = true; } }
Where [0] indicates the parent node on the tree menu to expand.
Notice that the code above, assumes you added a ScriptManager to your master page, therefore the pageLoad function will be called when the page is ready and the elements have been loaded.
Hope this works!
Juan
Thanks, I had also figured out a way to do it server side; however, that is the problem... Some of my nodes use NavigateURL to directly go to another page, and when that happens server-side code is never executed. Yea, I could make every node post-back but that seems wasteful.
So the only way I think I can accomplish this is to write a client-side Javascript(s) that basically does the same thing. It would have to go through the tree, get the Expanded status of each node with children, save that info somewhere (since we are client-side we can't get to session state so the only way I can think is to put it into a cookie); and then do the same thing server side also.
I haven't fully thought it out yet, and the Javascript code will be ugly (I don't write a lot of Javascript) but that is how I see it handling it client side.
Anyone got any other ideas as to how to handle this?
/Chimp (Tom)
To SimpTheChimp-
The way I solved my problem:
In the tree's _OnNodeSlectionChanged(bbject sender, Infragistics.WebUI.UltraWebNavigator.WebTreeNodeEventArgs e) event:
1) I got the parent and child nodes:
intParentNode = Convert.ToInt16(tvwSteps.SelectedNode.Parent.Index);intChildNode = Convert.ToInt16(tvwSteps.SelectedNode.Index);
2) I then added Response.Redirect - something like this: Response.Redirect("somepage.aspx?&nodeParent=" + intParentNode + "&nodeChild=" + intChildNode );
3) In my master page - or the one that contains your tree, I added the following in the Page_Load:
if (Request.QueryString["nodeParent"] != null) { TreeParentNode = Convert.ToInt16(Request.QueryString["nodeParent"]); }
if (Request.QueryString["nodeChild"] != null) { TreeChildNode = Convert.ToInt16(Request.QueryString["nodeChild"]); }
4) I then used TreeParentNode and TreeChildNode to select the node:
tvwSteps.SelectedNode = tvwSteps.Nodes[0].Nodes[treeParent].Nodes[treechild]; tvwSteps.SelectedNode.Expand(true);
I also have the same issue, in that I would like to maintain (or save/restore) the expanded/collapsed state between pages. I thought I could do it in the postback (by going thru the tree and saving the expanded property for any node that has children; then restore it in the page_load); but I forgot that some of my tree nodes use NavigateURL to go to different pages, and when that happens a postback doesn't occur.
So unless there is some way to get WebTree to save this in state, I figure it will have to be done manually. But that would require the use of Javascript to do this so that all nodes (even navigate nodes) save/restore the state properly.
Anyone else got any ideas? Any one from Infragistics? Any samples of Javascript to do this? Seems like it would be quite a bit of code.
BHervey -
Did you find a solution to this question about the Tree? I am having the same issue with my master page the tree not keeping its state after a postback.