Class PageTreeData

Base data control for accessing page tree's PageControlBase

Inheritance
System.Object
PageTreeData
Implements
System.Collections.Generic.IEnumerable<PageData>
System.Collections.IEnumerable
Namespace: EPiServer.Web.WebControls
Assembly: EPiServer.dll
Version: 8.11.0
Syntax
public class PageTreeData : Control, IEnumerable<PageData>, IEnumerable, IPageSource, IPageControl
Remarks

You can derive from this class to create custom controls generating any type of trees.

Constructors

PageTreeData()

Initializes a new instance of the PageTreeData class.

Declaration
public PageTreeData()

Properties

AutoBind

Gets or sets a value indicating whether the control should DataBind automatically before rendering if the state of the control allows it.

Declaration
public bool AutoBind { get; set; }
Property Value
Type Description
System.Boolean

true if control should DataBind automatically; otherwise, false.

CurrentPage

The current PageData.

Declaration
public PageData CurrentPage { get; }
Property Value
Type Description
PageData

EnableVisibleInMenu

Gets or sets whether the tree should filter page based on the "Visible in menus" property.

Declaration
public bool EnableVisibleInMenu { get; set; }
Property Value
Type Description
System.Boolean

EvaluateHasChildren

Gets or sets a value indicating whether a page should do an evaluation to see if it has children.

Declaration
public bool EvaluateHasChildren { get; set; }
Property Value
Type Description
System.Boolean

true if a page should do an evaluation to see if it has children; otherwise, false.

Remarks

Turning this check on results in a performance penalty since each page has to check for children.

ExpandAll

Expand all tree nodes.

Declaration
public bool ExpandAll { get; set; }
Property Value
Type Description
System.Boolean
Remarks

If ExpandAll is false, the branch where CurrentPage is located in is expanded. To find the right branch a search is being made from CurrentPage and up, towards the root page. Note, if a non-published page is encountered during the search and the current user is not allowed to access the page, the search fails and a login prompt is shown to the user.

If ExpandAll is true, all branches are expanded. The pages in the tree are crawled from top to bottom. If a non-published page is encountered in a branch and the current user is not allowed to access the page, that particular branch is not expanded any further.

FilterPagesWithoutTemplate

Gets or sets whether pages that does not have a template should be removed.

Declaration
public bool FilterPagesWithoutTemplate { get; set; }
Property Value
Type Description
System.Boolean
Remarks

Default value is true.

NumberOfLevels

Number of levels to show in tree.

Declaration
public int NumberOfLevels { get; set; }
Property Value
Type Description
System.Int32

OpenPages

The pages that should be expanded

Declaration
public PageReferenceCollection OpenPages { get; }
Property Value
Type Description
PageReferenceCollection

OpenTopPage

Gets the open top page.

Declaration
public PageReference OpenTopPage { get; }
Property Value
Type Description
PageReference

The open top page.

The root page to read data from

Declaration
public PageReference PageLink { get; set; }
Property Value
Type Description
PageReference

This example shows how to assign a value to the PageLink property of the PageTree control through code. This code is a modified version of the UserControl prefix.ascx.cs code-behind file in the EPiServer sample site.

We cannot assign to the PageLink property in the Page_Load event as it will be to late for the control to see it. Instead we use the Control.Init event.

PageLinkProperty

Set PageLinkProperty to automatically populate PageLink from a given property.

Declaration
public string PageLinkProperty { get; set; }
Property Value
Type Description
System.String
Remarks

Set to the name of the page property that you want to fetch the page link from.

Examples

This code snippet assumes that CalendarContainer is defined as a page type property of type Page reference.

<episerver:Calendar PageLinkProperty="CalendarContainer" runat="server" ID="Calendar1" />

PageLoader

Gets an HierarchicalPageLoader that is used for hierarchically loading pages.

Declaration
public HierarchicalPageLoader PageLoader { get; }
Property Value
Type Description
HierarchicalPageLoader

A HierarchicalPageLoader.

Remarks

By default, the loader will use the GetPage and GetChildren methods of the DataFactory to load a page and child pages for a given PageReference. This default behavior can be changed by setting the GetPageCallback and GetChildrenCallback properties.

PageSource

Set or get where pages will be fetched from, defaults to base page on databind.

Declaration
public IPageSource PageSource { get; set; }
Property Value
Type Description
IPageSource
Remarks

Normally you never need to modify PageSource, it will automatically be set.

PropertyResolver

Gets or sets the PropertyResolver that should be used by the current control instance.

Declaration
protected Injected<PropertyResolver> PropertyResolver { get; set; }
Property Value
Type Description
Injected<PropertyResolver>

PublishedStatus

Set or get the level of "publish status" filtering that will be done.

Declaration
public PagePublishedStatus PublishedStatus { get; set; }
Property Value
Type Description
PagePublishedStatus
Remarks

By default it will be set to Published, i e only pages that are published and is within the valid publish date range will be included.

RequiredAccess

Set or get the level of access rights filtering that will be done.

Declaration
public AccessLevel RequiredAccess { get; set; }
Property Value
Type Description
AccessLevel
Remarks

By default it will be set to AccessLevel.Read, i e only pages that you have read access to will be included.

Gets the PageReference that represents the root of the tree.

Declaration
public PageReference RootLink { get; }
Property Value
Type Description
PageReference

ShowRootPage

Gets or sets wheter to render the root page as part of the tree

Declaration
public virtual bool ShowRootPage { get; set; }
Property Value
Type Description
System.Boolean
Remarks

This setting is only useful when data is data bound to another control that does rendering of the tree structure.

SortBy

Gets or sets custom sorting on a property instead of using predefined sorting by setting SortOrder

Declaration
public string SortBy { get; set; }
Property Value
Type Description
System.String

SortDirection

Direction for sorting listings specified by SortBy

Declaration
public FilterSortDirection SortDirection { get; set; }
Property Value
Type Description
FilterSortDirection

SortOrder

Predefined sort orders instead of using custom sorting by setting SortBy

Declaration
public FilterSortOrder SortOrder { get; set; }
Property Value
Type Description
FilterSortOrder

Methods

Collapse(PageReference)

Collapse tree node, will automatically expand all parent nodes up to root page.

Declaration
public virtual void Collapse(PageReference closePage)
Parameters
Type Name Description
PageReference closePage

Page node to collapse.

CreatePostSortFilters()

Called once when the control needs access to post sort filters used for modifying a PageDataCollection.

Declaration
protected virtual void CreatePostSortFilters()
Remarks

Override this method to customize the population of filters to run after sorting occurs.

Typical use is to limit the number of pages, for example by using FilterCount or FilterSkipCount

CreatePreSortFilters()

Called once when the control needs access to pre sort filters used for modifying a PageDataCollection.

Declaration
protected virtual void CreatePreSortFilters()
Remarks

Override this method to customize the population of filters to run before sorting occurs.

Typical use is to add pages to create a combined list from two or more folders, or to remove pages based that should not appear in listing. For example by using FilterCompareTo

CreateSortFilters()

Called once when the control needs access to sort filters used for modifying a PageDataCollection.

Declaration
protected virtual void CreateSortFilters()
Remarks

Override this method to customize the population of sorting filters.

Typically used to change the order between pages, for example with FilterPropertySort.

CreateTemplateControl(PageData, ITemplate, Int32, Boolean)

Creates a template control based on template which is served with data from a PageData instance. If template is null no Control is added.

Declaration
protected void CreateTemplateControl(PageData page, ITemplate template, int level, bool hasChildren)
Parameters
Type Name Description
PageData page

The page.

System.Web.UI.ITemplate template

The template.

System.Int32 level

The indent level of the page.

System.Boolean hasChildren

Specifies whether the page has children or not.

DataBind()

Binds a data source to the invoked server control and all its child controls.

Declaration
public override void DataBind()

Expand(PageReference)

Expand tree node, will automatically expand all parent nodes up to root page.

Declaration
public virtual void Expand(PageReference openPage)
Parameters
Type Name Description
PageReference openPage

Page node to expand.

GetChildren(PageReference)

Retrieve a PageData listing

Declaration
public PageDataCollection GetChildren(PageReference pageLink)
Parameters
Type Name Description
PageReference pageLink

Reference to parent page

Returns
Type Description
PageDataCollection

Returns a collection of pages directly below the page referenced by the PageReference parameter.

Examples

The following code example demonstrates the usage of GetChildren.

GetEnumerator()

Returns an enumerator that iterates through the PageTreeData.

Declaration
public IEnumerator<PageData> GetEnumerator()
Returns
Type Description
System.Collections.Generic.IEnumerator<PageData>

A System.Collections.Generic.IEnumerator<EPiServer.Core.PageData> that can be used to iterate through the collection.

GetExpandedPages(PageReference)

Gets the expanded pages.

Declaration
protected virtual List<PageReference> GetExpandedPages(PageReference pageLink)
Parameters
Type Name Description
PageReference pageLink
Returns
Type Description
System.Collections.Generic.List<PageReference>

GetPage(PageReference)

Retrieves a PageData object with information about a page, based on the PageReference parameter.

Declaration
public PageData GetPage(PageReference pageLink)
Parameters
Type Name Description
PageReference pageLink

Reference to the page being retrieved

Returns
Type Description
PageData

PageData object requested

Examples

The following code example demonstrates how to get a start page.

The following code example demonstrates how to get a page by ID.

Gets a PageReference that represents the root of the tree. This method considers (in order) PageLinkProperty, PageLink and CurrentPage to establish the root. Override this method to add your own root lookup mechanism.

Declaration
protected virtual PageReference GetRootLink()
Returns
Type Description
PageReference

A PageReference representing the root in the tree.

IsExpanded(PageReference)

Determines whether the specified page is expanded. A page is considered expanded if the page is parent of the current page or the same as the current page and is part of the hierarchy having RootLink as root.

Declaration
protected virtual bool IsExpanded(PageReference page)
Parameters
Type Name Description
PageReference page

The page.

Returns
Type Description
System.Boolean

true if the specified page is expanded; otherwise, false.

IsExpanded(PageReference, PageHierarchyData)

Determines whether the specified page is expanded. A page is considered expanded if the page is parent of the current page or the same as the current page and is part of the hierarchy having RootLink as root.

Declaration
protected virtual bool IsExpanded(PageReference pageLink, PageHierarchyData pageHierarchyData)
Parameters
Type Name Description
PageReference pageLink

The page link.

PageHierarchyData pageHierarchyData

The page hierarchy data, used to check for children. If null PageSource is used to check for children instead

Returns
Type Description
System.Boolean

true if the specified page link is expanded; otherwise, false.

OnPreRender(EventArgs)

Raises the System.Web.UI.Control.PreRender event.

Declaration
protected override void OnPreRender(EventArgs e)
Parameters
Type Name Description
System.EventArgs e

An System.EventArgs object that contains the event data.

SetLoaderProperties()

Sets the loader properties. This method must be called prior to handing out the loader to the Hierarchical object model (PageHierarchicalEnumerable, PageHierarchicalView etc.)

Declaration
protected virtual void SetLoaderProperties()

Events

Filter

Exposes the Filter event of the underlying HierarchicalPageLoader.

Declaration
public event FilterEventHandler Filter
Event Type
Type Description
FilterEventHandler

Explicit Interface Implementations

IEnumerable.GetEnumerator()

Declaration
IEnumerator IEnumerable.GetEnumerator()
Returns
Type Description
System.Collections.IEnumerator

Implements

System.Collections.Generic.IEnumerable<T>
System.Collections.IEnumerable

Extension Methods