.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
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).
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 ;)
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??
.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! :-)
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.
Thanks for the fast reply Fourfinger.
I tried your suggestion, but got the exact same result :(
Any other ideas?
I'm sorry, I tried it out myself here, and it works.
So I'm unsure on how to fix this.
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).
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 ;)
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
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,
is working on a reply...