Copied to clipboard

Flag this post as spam?

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


  • Jimmy 7 posts 28 karma points
    Mar 15, 2012 @ 12:19
    Jimmy
    0

    .NET Calling Node.GetCurrent() always gives me the head node

    Hello everyone!

    I'm pretty new here and haven't had much time to look around, so I'm sorry if this is posted in the correct section, but I took a quick look and this seems as correct as I can get it :-)

    Anyway, so I have a usercontrol in C# .NET that I have included as a macro in Umbraco 4.7.1.1.

    This is a simplified version of it


    using umbraco.presentation.nodeFactory;

        public partial class webshopFlowPos : System.Web.UI.UserControl
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                Node currentNode = Node.GetCurrent();
                Response.Write(currentNode.Name);

             }

         }

    This macro is used on a content page called "imagePackage" that is listed under another one called "webshop", so basically it looks like this:

    root

    |

    -> webshop

          |-> imagePackage

     

    My problem is, that when the macro/usercontrol us loaded on the imagePackage page, the currentNode function always returns the name of the root node, and it doesn't seem to matter what page I visit or use it on ... it's always the same result.

    Could anyone possibly help me out with this?

    I searched around and found many people asking how to do it, and it seems to work for them, but maybe I am misunderstanding how to use it :S

     

    Thanks in advance for any reply! :-)

  • Fourfinger 24 posts 44 karma points
    Mar 15, 2012 @ 12:32
    Fourfinger
    0

    Just a wild guess, not sure at all, but try using "using umbraco.NodeFactory;" instead of presentation. It's a pain in my ass too.

  • Jimmy 7 posts 28 karma points
    Mar 15, 2012 @ 12:55
    Jimmy
    0

    Thanks for the fast reply Fourfinger.

    I tried your suggestion, but got the exact same result :(

    Any other ideas?

  • Fourfinger 24 posts 44 karma points
    Mar 15, 2012 @ 13:13
    Fourfinger
    0

    I'm sorry, I tried it out myself here, and it works.

            using umbraco.NodeFactory;  
         
    protected void Page_Load(object sender, EventArgs e)
            {
                litOutput.Text = Node.GetCurrent().Name;
            }

     

    So I'm unsure on how to fix this.

  • Jimmy 7 posts 28 karma points
    Mar 15, 2012 @ 13:29
    Jimmy
    0

    Thanks yet again for a fast reply Fourfinger.

    Could you maybe post your whole usercontroller?

     

    What I do is the following:

    1: Create a usercontroller in my /usercontrols folder in the umbraco root folder.

    http://pastebin.com/aM7hUENg

    2: Create a macro and simply choose the usercontroller that I just created

    3: Include it in my master page (I edit the files in visual studio) with the following line:

    <umbraco:macro ID="webShopFlowPos" alias="webShopFlowPos" runat="server"></umbraco:macro>

     

    The result I get is the root node, always, even if I navigate to the imagePackage.aspx (the place where the macro is included is the imagePackage file, so it will only display there, but still the wrong node).

  • Jimmy 7 posts 28 karma points
    Mar 15, 2012 @ 13:37
    Jimmy
    1

    oh ... I solved it =)

    The problem was the following:

    I accessed my file like this

    http://localhost/imagePackage.aspx

    When in reality I should have done it like this

    http://localhost/webshop-start/imagePackage.aspx

     

    Thanks for your replies Fourfingers, it eventually led me to finding the answer when you got it working with the same method, made me start looking for the error in other places ;)

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Mar 15, 2012 @ 13:42
    Tom Fulton
    0

    That sounds really strange.  Are you sure you're actually on the page you're expecting, and not just using it's template via an ?altTemplate or something like that?  What if you visit the page's URL directly by it's ID, ie /1158.aspx ?  Curious also if you get the same results in an XSLT macro via $currentPage.

    Also which node exactly is being returned, the webshop one?  Even from pages outside of that tree??

    -Tom

  • Fourfinger 24 posts 44 karma points
    Mar 15, 2012 @ 13:47
    Fourfinger
    0

    No problem! I was going to say the problem might be you use the macro in your masterpage, but guess I was wrong again! :)

    Glad it works,

Please Sign in or register to post replies

Write your reply to:

Draft