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