Try our conversational search powered by Generative AI!

Block Data from Master Template's Code Behind


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"]... ?

Dec 05, 2015 0:31


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;
Edited, Dec 07, 2015 9:42

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;
Dec 07, 2015 9:47
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.