November Happy Hour will be moved to Thursday December 5th.

Class PageControlBase

Serves as a base class for all controls that generate any type of PageData collection.

Inheritance
System.Object
PageControlBase
Implements
System.Collections.IEnumerable
System.ComponentModel.INotifyPropertyChanged
Namespace: EPiServer.Web.WebControls
Assembly: EPiServer.dll
Version: 9.12.2
Syntax
public abstract class PageControlBase : Control, IEnumerable, IPageSource, INotifyPropertyChanged, IPageControl
Remarks

Classes that derive from PageControlBase have very rich data binding support. First they support .NET data binding to for example System.Web.UI.WebControls.Repeater and System.Web.UI.WebControls.DataList.

Second, PageControlBase supports data binding itself to another data source to extend its data. Can be very useful to serializing data through different controls using different filters, for example when you need to split data delivered from a EPiServer.Web.WebControls.PageList into two different controls. You may also find that data delivered from one control would be better rendered using an other control.

Examples
  Simple example showing how data is read and displayed on a page. 
  The PageLink specifies which page the list will be retrieved from.
    <episerver:PageList MaxCount="1" PageLink="<%#CurrentPage.PageLink%>" runat="server" ID="PageList2">
<ItemTemplate>
<episerver:property PropertyName="PageName" runat="server"/>
<br/>
</ItemTemplate>
</episerver:PageList>
        Illustrates how data from one control can be used by several other controls, in this
        example it is only PageList1 that delivers data and the others are only used for presentation.
    <episerver:PageList PageLink="<%#CurrentPage.PageLink%>" runat="server" ID="PageList1"/>

<episerver:PageList MaxCount="1" DataSource="<%#PageList1%>" runat="server" ID="PageList3">
<ItemTemplate>
<episerver:property ID="Property1" PropertyName="PageName" runat="server"/>
<br/>
</ItemTemplate>
</episerver:PageList>

<episerver:PageList MaxCount="2" SkipCount="1" DataSource="<%#PageList1%>" runat="server" ID="PageList4">
<ItemTemplate>
<episerver:property ID="Property2" PropertyName="PageName" runat="server"/>
<br/>
</ItemTemplate>
</episerver:PageList>

<asp:Repeater DataSource="<%#PageList1%>" runat="server" ID="Repeater1">
<ItemTemplate>
<%#DataBinder.Eval(Container.DataItem,"PageName")%>
<br/>
</ItemTemplate>
</asp:Repeater>

Constructors

PageControlBase()

Initializes a new instance of PageControlBase

Declaration
protected PageControlBase()

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

Current loaded page for this web form

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

DataCount

Number of items in the control's list when the control is databound.

Declaration
public virtual int DataCount { get; }
Property Value
Type Description
System.Int32

DataSource

DataSource supports reading PageDataCollection from other controls using standard databinding through System.Collections.IEnumerable.

Declaration
public virtual object DataSource { get; set; }
Property Value
Type Description
System.Object
Remarks

If current control has any internal pages the will be appended after reading from DataSource

Used to serialize control containing data, or to rendering data from one control using another control

The root page to read data from

Declaration
public virtual 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.

        private void Page_Init(object sender, System.EventArgs e)
{
    // Set the tree to start at the site start page
    PageDataTree.PageLink = EPiServer.Core.PageReference.StartPage;
}

private void Page_Load(object sender, System.EventArgs e)
{
    //if (((EPiServer.PageBase)Page).CurrentPage["ListingContainer"] == null)
    //    MainBodyWidth = 410 + 170;
    // This is too late, we need to change the PageLink property in the Page_Init method
    // Pagedatatree1.PageLink = ((EPiServer.PageBase)Page).Configuration.StartPage;
}

private void InitializeComponent()
{
    this.Load += new System.EventHandler(this.Page_Load);
    this.Init += new System.EventHandler(this.Page_Init);
}

PageLinkProperty

Set PageLinkProperty to automatically populate PageLink from a given property.

Declaration
public virtual 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" />

PageSource

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

Declaration
public virtual 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.

RemoteSite

Set or get from which remote site pages will be fetched.

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

To fetch local pages, do not set this property.

If this property is set, the control will never load PageLinkProperty from any Block context.

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.

Methods

CreatePostSortFilters()

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

Declaration
protected abstract 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 abstract 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 abstract 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.

DataBind()

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

Declaration
public override void DataBind()

ExecFilters(PageDataCollection)

Call to execute filters on a given collection of pages

Declaration
protected void ExecFilters(PageDataCollection pages)
Parameters
Type Name Description
PageDataCollection pages

Collection to filter

GetChildren(PageReference)

Retrieve a PageData listing

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

Reference to parent page

Returns
Type Description
PageDataCollection

PageDataCollection with listed pages

Remarks

Filters will be executed against this collection.

GetChildren(PageReference, PageDataCollection)

Append a PageData listing to existing collection

Declaration
public virtual void GetChildren(PageReference pageLink, PageDataCollection pages)
Parameters
Type Name Description
PageReference pageLink

Reference to parent page

PageDataCollection pages

A page collection to append existing data

Remarks

Filters will be executed against this collection.

This version of GetChildren is useful when you have existing pages that need to be merged into the filtering proccess.

GetEnumerator()

Get a enumeration of the pages in contained PageDataCollection.

Declaration
public virtual IEnumerator GetEnumerator()
Returns
Type Description
System.Collections.IEnumerator
Remarks

Used to support standard data binding through System.Collections.IEnumerable

GetPage(PageReference)

Retrieve a PageData object

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

Reference to the page being retrieved

Returns
Type Description
PageData

PageData object requested

GetPages()

Get the PageDataCollection contained in this control

Declaration
protected PageDataCollection GetPages()
Returns
Type Description
PageDataCollection

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.

OnPropertyChanged(String)

Call when a properety has changed

Declaration
protected virtual void OnPropertyChanged(string propertyName)
Parameters
Type Name Description
System.String propertyName

Name of the property.

PopulatePages(PageDataCollection)

Called once when the control is populating the collection of pages

Declaration
protected abstract void PopulatePages(PageDataCollection pages)
Parameters
Type Name Description
PageDataCollection pages

Collection to populate with pages

Remarks

Override this method to customize the population of pages, if this control has been data bound the collection may already contain pages.

Examples

Example how a list control may choose to implement this method

protected override void PopulatePages(PageDataCollection pages)
{
    if(PageLink.ID!=0)
        GetChildren(PageLink,pages);
}

Events

Filter

Filters adding,removing or changing order of pages

Declaration
public event FilterEventHandler Filter
Event Type
Type Description
FilterEventHandler
Remarks

Filters can be called multiple times on different collections and should not contain any state.

If you add your own FilterPropertySort to the filter queue, make sure to set SortBy = null, otherwise the webcontrol's default sort filter is also executed and it would resort the data, since it is always executed last.

PropertyChanged

Occurs when a property is changed

Declaration
public event PropertyChangedEventHandler PropertyChanged
Event Type
Type Description
System.ComponentModel.PropertyChangedEventHandler

Implements

System.Collections.IEnumerable
System.ComponentModel.INotifyPropertyChanged

Extension Methods