NavBar with SiteMap and dynamic server templates

This post has 3 replies

Not Ranked
Posts: 13
igor.martincic Posted: Thu Aug 9, 2007 @ 5:25 AM
Hi, we're having problems with navbar on update panel. We want to achieve similar effect as word 2003. We've one navbar which shows sitemap's child node (only 1 level). When we click on a node we want to change selected node (via ajax updatepanel) on other navbar. When we dynamically load second navbar, it doesn't show server template (item's expanded property is set to true). This section is shown when user clicks on it. Server templates are populated on Page_Loaf event every time (even on postback). Navbar's output is a little weird (child is actually a server template): Parent Child When a user click's on Parent item it shows servertemplate on top of child, but child item (it's actually row) is still present. protected void nav1Level_ItemSelected(object sender, NavBarItemEventArgs e) { this.selectedNavigationItemID = e.Item.ID; // Set starting node in sitemap this.siteMap2Level.StartFromCurrentNode = false; this.siteMap2Level.StartingNodeUrl = SiteMapHelper.GetNodeByKey(e.Item.ID).Url; // Show sitemap in navbar this.nav2Level.DataSourceID = ""; this.nav2Level.DataSource = this.siteMap2Level; this.nav2Level.RenderRootItemId = e.Item.ID; this.nav2Level.DataBind(); // Cancel redirect e.Command = ""; e.Item.NavigateUrl = ""; // Try to select first item (it's not working) nav2Level.SelectedItem = nav2Level.Items[0]; pnlUpdate2Level.Update(); } Server templates are loaded on databound event. protected void nav2Level_ItemDataBound(object sender, NavBarItemDataBoundEventArgs e) { SiteMapNode siteMapNode = (SiteMapNode)e.DataItem; if (!String.IsNullOrEmpty(siteMapNode["ServerTemplateId"])) { e.Item.ServerTemplateId = siteMapNode["ServerTemplateId"]; } if (siteMapNode.Key == this.selectedNavigationItemID) { e.Item.Expanded = true; } else { e.Item.Expanded = false; } } Loading of server templates: private void AdministrationBasePage_AddNavigationServerTemplate(object sender, NavBarEventArgs e) { // Add organization schema template Control orgShemaTree = this.LoadControl("~/Administration//OrganizationUnitTree.ascx"); NavigationCustomTemplate template = new NavigationCustomTemplate(); GenericControlTemplate controlTemplate = new GenericControlTemplate(orgShemaTree); template.Template = controlTemplate; template.ID = "OrganizationShemaTemplate"; e.NavBar.ServerTemplates.Add(template); } public class GenericControlTemplate : ITemplate { private Control controlInstance; public GenericControlTemplate(Control controlInstance) { this.controlInstance = controlInstance; } public void InstantiateIn(Control container) { container.Controls.Add(this.controlInstance); } public Control ControlInstance { get { return this.controlInstance; } set { this.controlInstance = value; } } } Whar are we doing wrong? Is setting of servertemplateid property in ItemDataBound allowed? Is something wrong with our dynamic loading of server template? Best regards, Igor
Top 25 Contributor
Posts: 336
sadat Posted: Thu Aug 9, 2007 @ 12:12 PM
Try calling ReloadTemplate() on the NavBar on postback before you populate it.

   NavBar1.ReloadTemplate();
Not Ranked
Posts: 13
igor.martincic Posted: Fri Aug 10, 2007 @ 2:24 AM
Hello,

thanks for the help. It's working perfectly.

Best regards,
Igor
Top 25 Contributor
Posts: 179
conet Posted: Mon Nov 8, 2010 @ 2:26 AM
Solved the problem for me too...
I'm adding items with a server template with an update panel and the new item's server template was not shown until adding another new item.
Page 1 of 1 (4 items)