This may be really simple, but I'm trying to access a property within a block from the code behind in a master template (web forms).
For page properties, I've used something like ((PageBase)Page).CurrentPage.Property["propertyname"]...
Is there something similar to get a specific property from a block? (BlockData)Block).CurrentData.Property["x"]... ?
First I would recommend you to cast the CurrentPage object to its real type, or at least to a base class. However, this is how you access the block, given that the block is a property on CurrentPage:
This is usually how you would do it:
// a base class that always has the block property
var basePage = ((PageBase)Page).CurrentPage as PageBase;
if (basePage != null)
var value = basePage.YourBlockProperty.PropertyOnBlock;
Hmm can't edit my previous post, or at least not the code. The first snippet should have been:
And unfortunately I named the base class the same as the base class for pages :/ So I hope this makes it more clear:
// MetaDataPage is a base class that always has the block property
var metaPage = ((PageBase)Page).CurrentPage as MetaDataPage;
if (metaPage != null)
var value = metaPage.YourBlockProperty.PropertyOnBlock;