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://ko.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 forgot to mention that I am using this version of the controls:
14.1.20141.2150
.net 4.0
I also wrote a method to iterate through all items in the WebExplorerBar and to select an item based on the page name vs the value property of the item (called from the pre_render) and I can see the property being set, but it appears I just can't set the Selected item from the server side at all.
I 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 I can send along if you want.
Thanks,
Jeff
That fixed it, thanks Alex.
Hi lamecoder, Thanks for using Infragistics controls! I had a look at your code and I think I`ve found a solution for what you want to achieve.
You can use "OnInit" instead of "OnPreRender" event. This way your selection is preserved after navigating to the desired view.
The code should look like this:
<ig:WebExplorerBar ID="webNavigation" runat="server" GroupExpandBehavior="AnyExpandable" OnInit="webNavigation_OnInit" onitemselected="webNavigation_ItemSelected">
Please let me know if you have any further questions concerning this matter.
Sincerely, Alex M.Software Developer Infragistics, Inc. www.infragistics.com
Sample application is attached to the above previous post.
Thanks.
Hi Marina, thanks for replying. The sample is attached
Thanks
Hello Lamecoder,
Thank you for using our community.
If you could send me the simple test application that you have created, I would be able to better assist you.