public void Render() { if (!this.HasPermission) { return; } // Set the css class name of the menu item. base.CssClass = "NavigationMenuItem _BackgroundColor7"; base.Attributes.Add("Row", this.Row.ToString()); base.Attributes.Add("Position", this.Position.ToString()); // Check if a icon for the menu item is defined. if (this.XmlNode.Attributes["Icon"] != null) { // Create a new image web control to // display the menu item's icon. Image imgIcon = new Image(); imgIcon.Height = 60; // Set the image's source to the // defined source for the menu item. imgIcon.ImageUrl = this.XmlNode.Attributes["Icon"].Value; // Add the icon image to the menu // item control's child controls. base.Controls.Add(imgIcon); } // Add a line break between the image and the name. base.Controls.Add(new LiteralControl("<br />")); // Create a new label for the menu item's name. System.Web.UI.WebControls.Label lblName = new System.Web.UI.WebControls.Label(); // Check if a name for the menu item is defined. if (this.XmlNode.Attributes["Name"] != null) { // Set the language label's language key // to the menu item's defined name. lblName.Text = base.LanguageManager.GetText(this.XmlNode.Attributes["Name"].Value); } // Create a new panel for the menu items sub menu items. Panel pnlSubMenuItems = new Panel(); pnlSubMenuItems.ID = this.ID + "pnlSubMenuItems"; // Select all menu item definition xml nodes // of the menu item's sub menu items. XmlNodeList xmlNodes = this.XmlNode.SelectNodes("MenuItem"); // Run through all menu item definition xml nodes. foreach (XmlNode xmlNode in xmlNodes) { // Create a new menu item by the definition xml node. NavigationMenuItem item = new NavigationMenuItem( this.Owner, xmlNode, this ); // Hide the sub menu item. item.Style.Add("display", "none"); // Add the menu item control to the // child controls panel controls. pnlSubMenuItems.Controls.Add(item); item.Render(); } // Add the language label to the menu // item control's child controls. base.Controls.Add(lblName); base.Controls.Add(pnlSubMenuItems); // Check if a target page is defined for the menu item. if (this.XmlNode.Attributes["Target"] != null) { base.Attributes.Add("onclick", string.Format( "window.location = '{0}';", this.XmlNode.Attributes["Target"].Value )); if (this.Parent != null && HttpContext.Current.Request.Url.ToString().Contains(this.XmlNode.Attributes["Target"].Value)) { Page.ClientScript.RegisterStartupScript(this.GetType(), "ShowNavigationMenuSubItems", string.Format( "ShowNavigationMenuSubItems(document.getElementById('{0}'));", this.Parent.ClientID ), true); } } else if (this.XmlNode.Attributes["OnClick"] != null) { base.Attributes.Add("onclick", this.XmlNode.Attributes["OnClick"].Value); } else { base.Attributes.Add("onclick", string.Format( "ShowNavigationMenuSubItems(this);" )); } this.Attributes.Add("IdTable", this.Owner.ClientID + "Table"); if (this.Parent != null) { // Set the id of the menu item as parent menu item. this.Attributes.Add("IdParent", this.Parent.ClientID); } if (this.XmlNode.Attributes["IdContentPanel"] != null) { this.Attributes.Add("IdContentPanel", this.XmlNode.Attributes["IdContentPanel"].Value); } }
public void Render() { base.CssClass = "NavigationMenu"; // Create a new html table that contains the menu items. Table table = new Table(); table.ID = this.ID + "Table"; // Add the html table containing the menu items // to the navigation control's child controls. base.Controls.Add(table); // Select all menu item definition xml nodes on the root level. XmlNodeList xmlNodes = this.XmlDocument.DocumentElement.SelectNodes("MenuItem"); var maxRowIndex = 0; var maxCellIndex = 0; // Run through all menu item definition xml nodes. foreach (XmlNode xmlNode in xmlNodes) { // Create a new menu item by the definition xml node. NavigationMenuItem item = new NavigationMenuItem( this, xmlNode ); if (item.Row >= table.Rows.Count) { // Add a new table row to the table. table.Rows.Add(new TableRow()); } while (item.Position >= table.Rows[item.Row].Cells.Count) { // Add a new table cell to the table row. table.Rows[item.Row].Cells.Add(new TableCell() { CssClass = "TableCellNavigationMenuItem BorderColor1 Color1" }); } // Add the menu item control to the // defined position in the table table.Rows[item.Row].Cells[item.Position].Controls.Add(item); if (maxRowIndex < item.Row) { maxRowIndex = item.Row; } if (maxCellIndex < item.Position) { maxCellIndex = item.Position; } item.Render(); } for (int i = table.Rows[maxRowIndex].Cells.Count; i < (maxCellIndex + 1); i++) { // Add a new table cell to the table row. table.Rows[maxRowIndex].Cells.Add(new TableCell() { CssClass = "TableCellNavigationMenuItem BorderColor1 Color1" }); } }