/// <summary> /// 将此控件呈现给指定的输出参数,并使用指定的数据初始化控件。 /// </summary> /// <param name="writer"> 接收控件内容的 HtmlTextWriter 编写器 </param> /// <param name="MenuXML">菜单文件名。</param> public void RenderControl(HtmlTextWriter writer, string MenuXML) { Thinksea.WebControls.Menu2.Menu menuConnection = new Thinksea.WebControls.Menu2.Menu(MenuXML); // 菜单数据库联接。 string OutMenuHtmlText = // 输出菜单 HTML 文本。 @"<script type='text/javascript' id='clientEventHandlersJS'> <!-- function Thinksea_WebControls_Menu2_menuChange_" + this.ID + @"(obj,menu) { var controls = document.getElementById('" + this.ID + @"').all; for (var i=0; i < controls.length; i++) { if( controls[i].id == menu ) { menu = controls[i]; } } if(menu.style.display=='') {" ; if (this.MenuTitleCollapseStyle != null) { if (this.MenuTitleCollapseStyle.CssClass != null && this.MenuTitleCollapseStyle.CssClass != "") { OutMenuHtmlText = OutMenuHtmlText + @" obj.className='" + this.MenuTitleCollapseStyle.CssClass + @"';"; } string styleStr = this.StyleToCssString(this.MenuTitleCollapseStyle); if (styleStr != "") { OutMenuHtmlText = OutMenuHtmlText + @" obj.style.cssText='" + styleStr + @"';"; } } OutMenuHtmlText += @" menu.style.display='none'; }else{" ; if (this.MenuTitleStyle != null) { if (this.MenuTitleStyle.CssClass != null && this.MenuTitleStyle.CssClass != "") { OutMenuHtmlText = OutMenuHtmlText + @" obj.className='" + this.MenuTitleStyle.CssClass + @"';"; } string styleStr = this.StyleToCssString(this.MenuTitleStyle); if (styleStr != "") { OutMenuHtmlText = OutMenuHtmlText + @" obj.style.cssText='" + styleStr + @"';"; } } OutMenuHtmlText += @" menu.style.display=''; } } //--> </script>" ; System.Web.UI.WebControls.Panel MenuPanel = new System.Web.UI.WebControls.Panel(); MenuPanel.ID = this.ID; if (this.Style["Z-INDEX"] != null) { MenuPanel.Style["Z-INDEX"] = this.Style["Z-INDEX"]; } if (this.Style["POSITION"] != null) { MenuPanel.Style["POSITION"] = this.Style["POSITION"]; } if (this.Style["LEFT"] != null) { MenuPanel.Style["LEFT"] = this.Style["LEFT"]; } if (this.Style["TOP"] != null) { MenuPanel.Style["TOP"] = this.Style["TOP"]; } MenuPanel.ApplyStyle(this.ControlStyle); MenuPanel.Enabled = this.Enabled; MenuPanel.Visible = this.Visible; int menuGroupCount = 0; //菜单组数量 int menuItemCount; //菜单组中菜单项数量 Thinksea.WebControls.Menu2.MenuGroup [] mgis = menuConnection.GetMenuGroup( ); foreach (Thinksea.WebControls.Menu2.MenuGroup tmpmgis in mgis) { Thinksea.WebControls.Menu2.MenuItem [] miis = menuConnection.GetMenuItemOfMenuGroupIDWithAccessFilter(tmpmgis.ID, this.Powers); if (miis.Length > 0) { menuItemCount = 0; #region 菜单集合。 System.Web.UI.WebControls.Table MenuGroup = new System.Web.UI.WebControls.Table(); MenuGroup.Width = new System.Web.UI.WebControls.Unit("100%"); MenuGroup.CellSpacing = 0; MenuGroup.CellPadding = 0; #region 菜单组标题 System.Web.UI.WebControls.TableRow MenuGroupTitleRow = new System.Web.UI.WebControls.TableRow(); MenuGroupTitleRow.Style["CURSOR"] = "hand"; #region System.Web.UI.WebControls.TableCell MenuGroupTitleCell = new System.Web.UI.WebControls.TableCell(); if (tmpmgis.Expand) { MenuGroupTitleCell.ApplyStyle(this.MenuTitleStyle); } else { MenuGroupTitleCell.ApplyStyle(this.MenuTitleCollapseStyle); } MenuGroupTitleCell.Attributes["onclick"] = "Thinksea_WebControls_Menu2_menuChange_" + this.ID + "(this,'" + tmpmgis.ID.Replace("\"", "\\\"") + "');"; #region 填充菜单组标题 System.Web.UI.WebControls.Label TitleText = new System.Web.UI.WebControls.Label(); TitleText.ApplyStyle(this.MenuTitleOnMouseOutStyle); if (this.MenuTitleOnMouseOverStyle != null) { string styleStr = this.StyleToCssString(this.MenuTitleOnMouseOverStyle); if (styleStr != "") { TitleText.Attributes["onmouseover"] = "this.style.cssText='" + styleStr + "';"; } else { if (this.MenuTitleOnMouseOverStyle.CssClass != null && this.MenuTitleOnMouseOverStyle.CssClass != "") { TitleText.Attributes["onmouseover"] = "this.className='" + this.MenuTitleOnMouseOverStyle.CssClass + "';"; } } } if (this.MenuTitleOnMouseOutStyle != null) { string styleStr = this.StyleToCssString(this.MenuTitleOnMouseOutStyle); if (styleStr != "") { TitleText.Attributes["onmouseout"] = "this.style.cssText='" + styleStr + "';"; } else { if (this.MenuTitleOnMouseOutStyle.CssClass != null && this.MenuTitleOnMouseOutStyle.CssClass != "") { TitleText.Attributes["onmouseout"] = "this.className='" + this.MenuTitleOnMouseOutStyle.CssClass + "';"; } } } TitleText.Text = tmpmgis.Text; MenuGroupTitleCell.Controls.Add(TitleText); #endregion MenuGroupTitleRow.Cells.Add(MenuGroupTitleCell); #endregion MenuGroup.Rows.Add(MenuGroupTitleRow); #endregion #region 菜单项集合。 System.Web.UI.WebControls.TableRow MenuGroupRow = new System.Web.UI.WebControls.TableRow(); #region System.Web.UI.WebControls.TableCell MenuGroupCell = new System.Web.UI.WebControls.TableCell(); #region System.Web.UI.WebControls.Panel MenuGroupPanel = new System.Web.UI.WebControls.Panel(); MenuGroupPanel.ApplyStyle(this.MenuGroupStyle); MenuGroupPanel.ID = tmpmgis.ID; if (!tmpmgis.Expand) { MenuGroupPanel.Style["DISPLAY"] = "none"; } #region 填充菜单项 int CellMaxCount = this.MaxColumn; //用来控制每行最多显示的菜单项数量 int CellIndex = 0; //当前显示的菜单项行索引。用来辅助CellMaxCount完成控制每行显示的菜单项数量 foreach (Thinksea.WebControls.Menu2.MenuItem tmpmiis in miis) { #region 插入菜单项分隔符 if (this.ShowMenuItemSeparator && CellIndex > 0) { System.Web.UI.WebControls.Label menuItemSeparator = new System.Web.UI.WebControls.Label(); menuItemSeparator.ApplyStyle(this.MenuItemSeparatorStyle); MenuGroupPanel.Controls.Add(menuItemSeparator); } #endregion #region 菜单项 System.Web.UI.WebControls.HyperLink MenuItem = new System.Web.UI.WebControls.HyperLink(); MenuItem.ApplyStyle(this.MenuItemStyle); MenuItem.ID = tmpmiis.ID; MenuItem.Text = tmpmiis.Text; if (this.Enabled) { if (tmpmiis.URL.Length == 0) { MenuItem.NavigateUrl = "javascript:" + this.Page.ClientScript.GetPostBackEventReference(this, "ItemID_" + tmpmiis.ID); } else { MenuItem.Target = tmpmiis.Target; MenuItem.NavigateUrl = tmpmiis.URL; } if (this.ItemDataBound != null) { this.ItemDataBound(this, new Thinksea.WebControls.Menu2.ItemEventArgs(MenuItem, tmpmiis)); } } MenuGroupPanel.Controls.Add(MenuItem); #endregion menuItemCount++; CellIndex++; if (CellIndex >= CellMaxCount) { CellIndex = 0; System.Web.UI.WebControls.Literal MenuItemSplit = new System.Web.UI.WebControls.Literal(); MenuItemSplit.Text = "<br>"; MenuGroupPanel.Controls.Add(MenuItemSplit); } } #endregion MenuGroupCell.Controls.Add(MenuGroupPanel); #endregion MenuGroupRow.Cells.Add(MenuGroupCell); #endregion MenuGroup.Rows.Add(MenuGroupRow); #endregion if (menuItemCount > 0) { if (this.ShowMenuGroupSeparator && menuGroupCount > 0) { System.Web.UI.WebControls.Panel menuGroupSeparator = new System.Web.UI.WebControls.Panel(); menuGroupSeparator.ApplyStyle(this.MenuGroupSeparatorStyle); MenuPanel.Controls.Add(menuGroupSeparator); } MenuPanel.Controls.Add(MenuGroup); menuGroupCount++; } #endregion } } writer.Write(OutMenuHtmlText); MenuPanel.RenderControl(writer); }
protected override void RenderBeginTag(HtmlTextWriter writer) { Menu owner = Control; // skip link if (owner.SkipLinkText.Length != 0) { HyperLink skipLink = new HyperLink(); skipLink.NavigateUrl = '#' + owner.ClientID + "_SkipLink"; skipLink.ImageUrl = owner.SpacerImageUrl; skipLink.Text = owner.SkipLinkText; skipLink.Height = Unit.Pixel(1); skipLink.Width = Unit.Pixel(1); skipLink.Page = Page; skipLink.RenderControl(writer); } _menuPanel = new Panel(); _menuPanel.ID = owner.UniqueID; _menuPanel.Page = Page; // Determine root menu style MenuItem titleItem; if (_path != null) { titleItem = owner.Items.FindItem(_path.Split(TreeView.InternalPathSeparator), 0); _titleItem = titleItem; } else { titleItem = owner.RootItem; } SubMenuStyle rootMenuStyle = owner.GetSubMenuStyle(titleItem); if (!rootMenuStyle.IsEmpty) { if (Page != null && Page.SupportsStyleSheets) { string styleClass = owner.GetSubMenuCssClassName(titleItem); if (styleClass.Trim().Length > 0) { _menuPanel.CssClass = styleClass; } } else { _menuPanel.ApplyStyle(rootMenuStyle); } } _menuPanel.Width = owner.Width; _menuPanel.Height = owner.Height; _menuPanel.Enabled = owner.IsEnabled; _menuPanel.RenderBeginTag(writer); }
/// <summary> /// Creates the control sub-components of the /// control. /// </summary> /// <remarks> /// Sets the user <see cref="_contentCell"/> container /// object render delegate as the /// <see cref="RenderPanelContent"/> method using the /// <see cref="Control.SetRenderMethodDelegate"> /// SetRenderMethodDelegate</see> method. This allows /// the content (this panel control) to be rendered as a /// child object of the <see cref="_contentCell"/> container. /// </remarks> private void CreateControlComponents() { // Create the header panel and // set its state to this control state. _headerPanel = new Panel(); _headerPanel.ID = this.HeaderPanelId; _headerPanel.Visible = this.Visible; _headerPanel.Width = this.Width; _headerPanel.Height = this.Height; foreach(string key in this.Attributes.Keys) { string val = this.Attributes[key]; _headerPanel.Attributes.Add(key, val); } _headerPanel.ToolTip = this.ToolTip; _headerPanel.ApplyStyle(this.ControlStyle); // Ensures that if a border is required, // the content panel (this) does not get a // second border. this.BorderStyle = BorderStyle.NotSet; // Create the hidden input and set the // control collapsed state value. _currentState = new HtmlInputHidden(); _currentState.ID = this.CollapsedStateId; _currentState.Value = this.Collapsed ? "true" : "false"; // Create the control table container. _controlTable = new HtmlTable(); _controlTable.ID = this.ID + "_Table"; _controlTable.Width = "100%"; _controlTable.CellSpacing = 0; _controlTable.CellPadding = 2; _controlTable.Visible = true; // Create the header container row. _headerRow = new HtmlTableRow(); _headerRow.ID = this.ID + "_HeaderRow"; _headerRow.Visible = true; // Create the title cell. _titleCell = new HtmlTableCell(); _titleCell.ID = this.ID + "_TitleCell"; _titleCell.Align = "left"; _titleCell.Width = "90%"; _titleCell.Visible = true; // Set the style of the cell to the TitleStyle. ApplyStyle(_titleCell, this.TitleStyle); // Create the title link. _titleLink = new HyperLink(); _titleLink.ID = this.ID + "_TitleLink"; _titleLink.Text = this.TitleText; // Set the style of the link to the TitleStyle. _titleLink.ApplyStyle(this.TitleStyle); _titleLink.Visible = true; // Create the action cell. _actionCell = new HtmlTableCell(); _actionCell.ID = this.ID + "_ActionCell"; _actionCell.Align = "right"; _actionCell.Width = "10%"; _actionCell.Visible = true; _actionCell.NoWrap = true; // Set the style of the cell to the TitleStyle. ApplyStyle(_actionCell, this.TitleStyle); // Create the action link. _actionLink = new HyperLink(); _actionLink.ID = this.ID + "_actionLink"; // Set the style of the link to the TitleStyle. _actionLink.ApplyStyle(this.TitleStyle); // Create the row container for this control. _contentRow = new HtmlTableRow(); _contentRow.ID = this.ID + "_ContentRow"; _contentRow.Visible = true; // Create the cell container for this control. _contentCell = new HtmlTableCell(); _contentCell.ID = this.ID + "_ContentCell"; _contentCell.ColSpan = 2; _contentCell.Align = "left"; _contentCell.Visible = true; // Set the render method for this control panel. // This allows us to render this control (user content panel) // as a child of the content cell. _contentCell.SetRenderMethodDelegate( new RenderMethod(RenderPanelContent)); }