Get page data for current page.

Namespace:  EPiServer
Assembly:  EPiServer (in EPiServer.dll) Version: 5.2.375.236

Syntax

C#
[DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden)]
[BrowsableAttribute(false)]
public virtual PageData CurrentPage { get; set; }

Field Value

A PageData object, null if failure.

Implements

IPageSource..::.CurrentPage
ICurrentPage..::.CurrentPage

Remarks

Abstract property, must be implemented in derived classes.

A little caution is necessary when using CurrentPage in the HTML part of Web forms, as CurrentPage is implemented from IPageSource and UserControlBase also implements IPageSource. This means that CurrentPage will have different meanings in the same Web form depending on whether it's used outside any included EPiServer Web custom control in general and outside any templated EPiServer Web custom control in particular.

Examples

The following code example demonstrates the usage of both CurrentPage and Configuration. The example is used in EPiServer's sample Web site to send e-mail. Configuration is used to initalize the mail server and also, together with CurrentPage, to send information to the recipient of the e-mail.
CopyC#
protected TextBox To, From, Subject, Other;

protected void SendEmailButton_Click(object sender, System.EventArgs e) 
{
    if (!IsValid)
        return;

    MailMessage mail = new MailMessage();
    mail.IsBodyHtml = false;
    mail.From = new MailAddress(From.Text);
    mail.To.Add(To.Text);
    mail.Subject = Subject.Text;
    System.Text.StringBuilder sb = new System.Text.StringBuilder();
    sb.Append(Other.Text).
        Append("\n\n").
        Append(EPiServer.Configuration.Settings.Instance.SiteUrl.Host).
        Append(CurrentPage.LinkURL).
        Append("\n\nMessage was sent from IP address ").
        Append(Request.UserHostAddress).
        Append(" at ").
        Append(DateTime.Now.ToString());

    mail.Body = sb.ToString();

    new SmtpClient().Send(mail);
    string key = "CloseWindow";
    string script = "<script type='text/javascript'>window.returnValue = true;window.parent.close();</script>";
    Page.ClientScript.RegisterStartupScript(this.GetType(), key, script);
}
The following example demonstrates the usage of CurrentPage on a page template file, outside of any included controls.
Copy 
<%= CurrentPage.PageName %>
The following example demonstrates the usage of CurrentPage on a page template file, inside ContentFramework and Content controls.
Copy 
<development:DefaultFramework id="DefaultFramework" runat="server">
    <EPiServer:Content ID="NewsListing" Region="menuRegion" runat="server">
        CurrentPage.PageName on a page template file, inside ContentFramework and Content controls:
        <%= CurrentPage.PageName %>
        ...
The following example demonstrates the usage of CurrentPage inside an EPiServer templated control.
Copy 
<EPiServer:Newslist ID=Newslistnew Pagelinkproperty="NewsContainer" runat="server" MaxCount='<%# GetNewsCount() %>'>
    <NewsTemplate>
        CurrentPage.PageName on a page template file, inside Newslist control (in NewsTemplate):
        <%= CurrentPage.Page %>
    </NewsTemplate>
</EPiServer:Newslist>
The following code example demonstrates the usage of CurrentPage and IsValue. CurrentPage is used to read the content of two properties; NewsCount and MainImage. To safeguard the property access, the presence and possible contents of both properties are first tested using the IsValue method.
CopyC#
protected int GetNewsCount()
{
    return IsValue("NewsCount") ? (int)CurrentPage["NewsCount"] : -1;
}

protected string StartPageImage
{
    get
    {
        return IsValue("MainImage") ? (string)CurrentPage["MainImage"] : _startPageImage;
    }
}

See Also