I am using the WebExplorerBar in a MasterPage for navigation and I need to maintain the state (both the expanded and selected items) of the WebExplorerBar between postbacks and page navigations. I looked at this example:
http://es.infragistics.com/community/forums/t/47906.aspx
There were 2 issues with this example:
1) It didn't handle group child items having child items themselves
2) It did not save/restore the selected node properly (expanded was working as long as group child items did not have child items)
I wrote a class to save the state (expanded/selected), which I store in the session and use to keep the state of the WebExplorerBar. I works fine for the Expanded property of all of the nodes, but the Selected issue from the example remains (the selected node in the WebExplorerBar sometimes works, sometimes it defaults to the first item, sometimes it selects the previously selected item.) I have verified that my code for saving/setting the state works properly for Expanded and also works properly for Selected (it only sets one node to be Selected and it is the previously selected node).
It seems like something on the client side is changing the highlighted node after I have set the Selected property (expanded state of all node is restored correctly). Can someone help me with this?
// Class to save state
public class WebExplorerBarItemState { public bool NodeState { get; set; } public bool Selected { get; set; } public List<WebExplorerBarItemState> ItemStates = new List<WebExplorerBarItemState>(); } /// <summary> /// Class to save the state (expanded/selected) of all nodes in the WebExplorerBar /// control so we can restore it across pages. /// </summary> public class WebExplorerBarSate { public List<WebExplorerBarItemState> _groupStates = new List<WebExplorerBarItemState>(); public WebExplorerBarSate(WebExplorerBar webExplorer) { foreach (ExplorerBarGroup group in webExplorer.Groups) { WebExplorerBarItemState groupState = new WebExplorerBarItemState(); groupState.NodeState = group.Expanded; groupState.Selected = group.Selected; _groupStates.Add(groupState); if (group.HasChildren) GetItemStates(group.Items, groupState); } } private void GetItemStates(ExplorerBarItemCollection items, WebExplorerBarItemState itemState) { foreach (ExplorerBarItem subItem in items) { WebExplorerBarItemState subItemState = new WebExplorerBarItemState(); subItemState.NodeState = subItem.Expanded; subItemState.Selected = subItem.Selected; itemState.ItemStates.Add(subItemState); if (subItem.HasChildren) GetItemStates(subItem.Items, subItemState); } } public static void SetWebExplorerBarState(WebExplorerBar webExplorer, WebExplorerBarSate webState) { foreach (ExplorerBarGroup group in webExplorer.Groups) { group.Expanded = webState._groupStates[group.Index].NodeState; group.Selected = webState._groupStates[group.Index].Selected; if (group.HasChildren) SetItemStates(group.Items, webState._groupStates[group.Index]); } } private static void SetItemStates(ExplorerBarItemCollection items, WebExplorerBarItemState itemState) { foreach (ExplorerBarItem subItem in items) { subItem.Expanded = itemState.ItemStates[subItem.Index].NodeState; subItem.Selected = itemState.ItemStates[subItem.Index].Selected; if (subItem.HasChildren) SetItemStates(subItem.Items, itemState.ItemStates[subItem.Index]); } } }
// Master page event handlers
protected void webNavigation_ItemSelected(object sender, Infragistics.Web.UI.NavigationControls.ExplorerBarItemSelectedEventArgs e) { // Store the state (selected/expanded) of the nav menu Session["_WebExplorerState_Master_"] = new WebExplorerBarSate(webNavigation); string redirectURL = e.NewSelectedItem.Value.ToString(); if (redirectURL != "") { Response.Redirect(redirectURL); } } protected void webNavigation_PreRender(object sender, EventArgs e) { // Restore the state (selected/expanded) of the nav menu WebExplorerBarSate state = (WebExplorerBarSate)(Session["_WebExplorerState_Master_"]); if (state != null) { WebExplorerBarSate.SetWebExplorerBarState(webNavigation, state); } }
// WebExplorerBar control in master page
<igb:WebExplorerBar ID="webNavigation" runat="server" GroupExpandBehavior="AnyExpandable" OnPreRender="webNavigation_PreRender" onitemselected="webNavigation_ItemSelected"> <Groups> <igb:ExplorerBarGroup Text="Home" ImageUrl="./images/icon_home_gray.png" Value="./main.aspx" Selected="true"> </igb:ExplorerBarGroup> <igb:ExplorerBarGroup Text="Status" ImageUrl="./images/icon_status_gray.png"> <Items>
...................................................
</igb:ExplorerBarGroup> </Groups> <AutoPostBackFlags ItemClick="Off" ItemSelected="On" /> </igb:WebExplorerBar>
I am using this version of the controls:
14.1.20141.2150
.net 4.0
I also tried using version 14.2.20142.2480 of the control and have the same issue. I created a simple test application that shows the issue that is attached. I created a previous post similar to this, but replies from other people seemed to be getting deleted from the thread so I am reposting.
Sample application is attached to the previous post. Thanks
Is anyone able to help me with this?
Thanks
Hi Ivaylo. You gave me the solution for it in this thread:
http://es.infragistics.com/community/forums/t/103167.aspx
I started that thread because this one didn't get a response.
Hello,
It has being a while and yet, please let me know in case you still have an issue with this!