Context-aware property?

Vote:
 

Is there a way for a custom property type (and/or it's control) to know which page it is being edited for? I've been digging through reflector and the only connection to a PageData I can find is an internal property which I can't access :(

What I want to do is to create a property which lets the user select from common values (or enter a custom value). I have already done this by getting existing values for the property type, which requires no knowledge of what page is currently being edited. But I now have a new requirement that the set of common values should be gathered only from a subtree of the site, which means I somehow have to find out where the page sits (or is being created).

As I can't find a way to do this I have these alternate solutions but I don't think neither one is very good:
1. Use different page types (with the same page template) for the different subtrees. Through the PropertyData.PageDefinitionID it is at least theoretically possible to find the page type. Then I can have some kind of map of page types to start nodes for the subtrees.
2. Use different page types and add a dummy property to the page type signalling either by it's name or default value which subtree it should be used in. PropertyData.InitializeData gets the full PropertyDataCollection and should be able to find this dummy property.

Ideas?

#39657
May 27, 2010 12:27
Vote:
 

Ah, I should also be able to look at the QueryString, which in edit mode holds either the page ID or its parent (for a new page). The PropertyData itself knows if it is dynamic or a page property so I can use this if I need to do something differently for dynamic properties.

If anyone's got another idea I'm still interested though :)

#39659
Edited, May 27, 2010 12:31
Vote:
 

Hi Magnus,

Could this help you out?

var page = HttpContext.Current.Handler as EPiServer.PageBase;
if (page != null)
{
    return page.CurrentPage;
}
#39668
May 27, 2010 14:22
Vote:
 

Superb, that should work. The handler is actually of type EPiServer.UI.Edit.EditPanel which overrides CurrentPage and makes sure it is set for new pages as well (the page id will be 0, but ParentLink should be correct which is enough for my needs).

Thanks!

Edit: Tried to fix ugly fonts

#39673
Edited, May 27, 2010 14:39
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.