Skip to content

Instantly share code, notes, and snippets.

@PNergard
Created September 21, 2015 19:55
Show Gist options
  • Save PNergard/d482296183dbe0121239 to your computer and use it in GitHub Desktop.
Save PNergard/d482296183dbe0121239 to your computer and use it in GitHub Desktop.
using EPiServer;
using EPiServer.Core;
using EPiServer.Editor;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using System.Web.UI.WebControls;
namespace Nergard.WebControls
{
/// <summary>
/// WebControl to manage creation of bootstrap rows. All childcontrols which are not of type EPiServer Property is removed. All EPiServer innerproperties are checked for null.
/// If no children of type Property or if all innerproperty values is null the row isn't rendered.
/// </summary>
public class BootstrapRowControl : Panel
{
protected override void OnInit(EventArgs e)
{
//Empty contentareas must be visible in edit mode.
if (PageEditing.PageIsInEditMode) return;
PageData contentPage = null;
for (int x = this.Controls.Count - 1; x >= 0; x--)
{
var control = this.Controls[x] as EPiServer.Web.WebControls.Property;
if (control != null)
{
if (control.PageLink != null && control.PageLink != PageReference.EmptyReference && !string.IsNullOrEmpty(control.PageLink.ToString()))
contentPage = DataFactory.Instance.GetPage(control.PageLink);
else if (!string.IsNullOrEmpty(control.PageLinkProperty) && CurrentPage[control.PageLinkProperty] != null)
contentPage = DataFactory.Instance.GetPage(new PageReference(CurrentPage[control.PageLinkProperty].ToString()));
else
contentPage = CurrentPage;
if (contentPage == null || contentPage[((EPiServer.Web.WebControls.Property)control).PropertyName] == null)
this.Controls.RemoveAt(x);
}
else
this.Controls.RemoveAt(x);
}
if (this.Controls.Count == 0)
this.Visible = false;
}
/// <summary>
/// Currentpage from HttpContext
/// </summary>
private static PageData CurrentPage
{
get
{
var page = HttpContext.Current.Handler as EPiServer.PageBase;
if (page == null)
{
return null;
}
return page.CurrentPage;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment