/// <summary> /// Gets the initial collection of webpart panels. /// </summary> /// <returns></returns> protected internal virtual WebPartPanelCollection GetInitialWebPartPanels() { WebPartPanelCollection panels = new WebPartPanelCollection(); if (this.zoneTemplate != null) { // Create the control which contains the template. NonParentingControl templatedControl = new NonParentingControl(); this.zoneTemplate.InstantiateIn(templatedControl); // Don't do anything with an empty template. if (!templatedControl.HasControls()) { return(panels); } WebPartPanel panel; int zoneIndexCounter = 0; foreach (Control childControl in templatedControl.Controls) { panel = this.CreateWebPartPanel(childControl); if (panel != null) { panel.ZoneIndex = (zoneIndexCounter++); panels.Add(panel); } } } return(panels); }
/// <summary> /// Adds the webpart panels in the specified zone to the current collection. /// </summary> /// <param name="zone"></param> internal void AddWebPartPanelsFromZone(WebPartZone zone) { WebPartPanelCollection panels = zone.GetInitialWebPartPanels(); foreach (WebPartPanel panel in panels) { base.Add(panel); } }
/// <summary> /// Moves a webpart panel to the specified zone at the specified index. /// </summary> /// <param name="panel"></param> /// <param name="zone"></param> /// <param name="zoneIndex"></param> public void MoveWebPartPanel(WebPartPanel panel, WebPartZone zone, int zoneIndex) { WebPartPanelCollection panels = zone.WebPartPanels; if (zoneIndex < 0) { throw new ArgumentOutOfRangeException("zoneIndex"); } // Update the indices of the webpart panels which are placed beneath the moved panel. for (int i = zoneIndex; i < panels.Count; i++) { panels[i].ZoneIndex++; } panel.ZoneID = zone.ID; panel.ZoneIndex = zoneIndex; }
/// <summary> /// Gets the webparts for the specified zone. /// </summary> /// <param name="zone"></param> /// <returns></returns> internal WebPartPanelCollection GetWebPartsForZone(WebPartZone zone) { WebPartPanelCollection panels = new WebPartPanelCollection(); // Get the webpart panel's in the zone sorted by the the zone index. SortedList <WebPartPanel, object> sortedPanels = new SortedList <WebPartPanel, object>(new WebPartManager.WebPartPanelZoneIndexComparer()); foreach (WebPartPanel panel in this.Controls) { if (panel.ZoneID == zone.ID && !panel.IsRemoved) { sortedPanels.Add(panel, null); } } // Re-organize the zone indices, starting from 0. for (int i = 0; i < sortedPanels.Keys.Count; i++) { sortedPanels.Keys[i].ZoneIndex = i; panels.Add(sortedPanels.Keys[i]); } return(panels); }
/// <summary> /// Renders the child controls. /// </summary> /// <param name="writer"></param> protected override void RenderChildren(HtmlTextWriter writer) { WebPartPanelRenderer renderer = this.CreateWebPartPanelRenderer(); if (renderer == null) { throw new InvalidOperationException("No webpart panel renderer specified."); } WebPartPanelCollection panels = this.WebPartPanels; bool supportsClientDragDrop = WebPartManager.SupportsClientSideDragDrop(this.Page); bool horizontal = (this.orientation == Orientation.Horizontal); if (horizontal) { writer.RenderBeginTag(HtmlTextWriterTag.Tr); } // Render the panels. foreach (WebPartPanel panel in panels) { if (!horizontal) { writer.RenderBeginTag(HtmlTextWriterTag.Tr); } writer.AddAttribute(HtmlTextWriterAttribute.Id, panel.ContainerClientID); writer.AddAttribute("relatedWebPart", panel.ClientID); if (supportsClientDragDrop) { writer.AddAttribute("orientation", this.Orientation.ToString()); writer.AddAttribute("ondragenter", "MoveWebPartDragEnter(this);"); writer.AddAttribute("ondragend", "MoveWebPart(this, dropLocation);"); writer.AddAttribute("ondragover", "MoveWebPartDragOver(this, true);"); } writer.RenderBeginTag(HtmlTextWriterTag.Td); renderer.RenderWebPartPanel(writer, panel); writer.RenderEndTag(); if (!horizontal) { writer.RenderEndTag(); } } if (!horizontal) { writer.RenderBeginTag(HtmlTextWriterTag.Tr); } // Render the control which will be displayed when there are no panels in the zone. if (WebPartManager.SupportsClientSideDragDrop(this.Page)) { writer.AddAttribute("ondragenter", "MoveWebPartDragEnter(this);"); writer.AddAttribute("ondragover", "MoveWebPartDragOver(this, 'False');"); writer.AddAttribute("orientation", this.Orientation.ToString()); } writer.RenderBeginTag(HtmlTextWriterTag.Td); // Render the message which will be made visible when no panels are placed inside this zone. this.emptyZoneMessage.Attributes["name"] = "emptyWebPartZone"; this.emptyZoneMessage.Attributes["webPartsInZone"] = this.WebPartPanels.Count.ToString(); if (this.WebPartPanels.Count > 0) { this.emptyZoneMessage.Style.Add(HtmlTextWriterStyle.Display, "none"); } this.emptyZoneMessage.RenderControl(writer); writer.RenderEndTag(); writer.RenderEndTag(); }