Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Murray Roke 503 posts 967 karma points c-trib
    Dec 21, 2010 @ 22:04
    Murray Roke
    0

    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

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Dec 21, 2010 @ 22:13
    Tom Fulton
    2

    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

  • Murray Roke 503 posts 967 karma points c-trib
    Dec 22, 2010 @ 00:19
    Murray Roke
    0

    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.

  • Murray Roke 503 posts 967 karma points c-trib
    Dec 22, 2010 @ 00:46
    Murray Roke
    0

    oh actually, this only works in inline script blocks in the aspx. it does not work in code behind, ... not for me anyway.

  • Masood Afzal 176 posts 522 karma points
    Dec 22, 2010 @ 01:27
    Masood Afzal
    0

    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

     

     

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Dec 22, 2010 @ 01:28
    Tom Fulton
    2

    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

    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?

     

  • Murray Roke 503 posts 967 karma points c-trib
    Dec 22, 2010 @ 02:24
    Murray Roke
    0

    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.

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Dec 22, 2010 @ 02:57
    Tom Fulton
    0

    Haha..oops, it's right there in the title of the post too!

    Glad you got it sorted :)

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies