You should be able to use something like the following to get a property from the parent:
Node parentNode = new Node(Node.GetCurrent().Parent.Id); string val = parentNode.GetProperty("propertyAlias").Value.ToString();
Theoretically you could just use Node.GetCurrent().Parent.GetProperty("propertyAlias").Value.ToString(); but I think I read about this not working recently, could be wrong though
Generally you want to access published content when you are working in the front end. Usually you only access unpublished content if you are developing a datatype/control for the backend. But if you want unpublished content, I think its pretty much the same but using the Document API instead of nodeFactory
using umbraco.cms.businesslogic.web; .... Document d = new Document(Node.GetCurrent().Parent.Id); string val = d.getProperty("propertyAlias").Value.ToString();
This assumes the current node is published...or is this for the backend? If so you can get the current ID using the "id" querystring.
Document curDoc = new Document(Convert.ToInt32(HttpContext.Current.Request["id"])); Document parentDoc = new Document(curDoc.ParentId);
Can't think of any reason it wouldn't work from codebehind, are you getting an error?
Getting Data from a parent node from within a Custom Datatype using the User Control Wrapper
Hi all
I have a user control which implements "umbraco.editorControls.userControlGrapper.IUsercontrolDataEditor"
It renders a drop down list of products.
I'd like to filter the list of productsbased on a 'category' property in a parent node.
Is there any way to do this?
a) with the wrapper: umbraco.editorControls.userControlGrapper.IUsercontrolDataEditor
b) with the full DataType: IDataType
You should be able to use something like the following to get a property from the parent:
Theoretically you could just use Node.GetCurrent().Parent.GetProperty("propertyAlias").Value.ToString(); but I think I read about this not working recently, could be wrong though
Oh duh too easy, I thought I tried that... um.... yea it's 99% there, but it uses the published content... hmm that will probably work fine. thanks.
If you have a solution that uses 'unpublished' content that may be useful, not sure what my requirements should be for that scenario...hmmm.
oh actually, this only works in inline script blocks in the aspx. it does not work in code behind, ... not for me anyway.
Node.GetCurrent() will work in code behind if you are using correct namespaces and references.
For unpublished contents, you can use 'Document' instead of 'Node'
namespace for Node : umbraco.presentation.nodeFactory
namespace for Document: umbraco.cms.businesslogic.web
Hi,
Generally you want to access published content when you are working in the front end. Usually you only access unpublished content if you are developing a datatype/control for the backend. But if you want unpublished content, I think its pretty much the same but using the Document API instead of nodeFactory
This assumes the current node is published...or is this for the backend? If so you can get the current ID using the "id" querystring.
Can't think of any reason it wouldn't work from codebehind, are you getting an error?
I'm working in the BackOffice, which is implied by the fact I'm working with a "umbraco.editorControls.userControlGrapper.IUsercontrolDataEditor" :-)
ahhhh use the ole querystring, yea that's a simple answer I should have thought of too ;-]
I should change which one is the correct answer, but I can't :-\
Thanks Tom.
Haha..oops, it's right there in the title of the post too!
Glad you got it sorted :)
is working on a reply...