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

tif picture tif · Mar 30, 2011 · Viewed 7.4k times · Source

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

Answer

Mikael Östberg picture Mikael Östberg · Mar 30, 2011

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.