tif
tif

Reputation: 1149

How to get the "Page type" for the current page. EPiServer

How can I get the Page Type for the current page. I tried

CurrentPage.GetType();

but no success. I need to check if the Page Type equals a specific type in order to do something or not.

Thanks

Upvotes: 2

Views: 9111

Answers (4)

tompipe
tompipe

Reputation: 949

With a page type builder strongly typed class you can use the C# is keyword

e.g

if (CurrentPage is SomeStronglyTypeClass) 

Upvotes: 5

Ted Nyberg
Ted Nyberg

Reputation: 7391

If you're using Page Type Builder you can also use the PageTypeResolver class.

Upvotes: 2

Mari
Mari

Reputation: 61

CurrentPage.PageTypeName gives you the name of the PageType

Upvotes: 3

Mikael Östberg
Mikael Östberg

Reputation: 17156

You need to check the PageTypeName or PageTypeID properties, like this:

if(CurrentPage.PageTypeName == "StartPage")
    // Do something

Check the reference: http://sdk.episerver.com/library/cms5/html/AllMembers_T_EPiServer_Core_PageData.htm

The GetType() method is declared on System.Object and returns the System.Type for the object. Is is available on all types in the .NET Framework since all types inherit from System.Object.

Upvotes: 8

Related Questions