Response.Redirect to next preceding sibling with umbraco.NodeFactory GetNodeByXpath from .net Usercontrol
I want to redirect customers from one page to its first preceding sibling from .NET usercontrol. This is my code but I get exception "$currentPage/preceding-siblings::* [@isDoc][1] **has an invalid token**."
I tried more ways, nothing works and I don't want to go with too long solutions. I can't figure out what is wrong in my code, any ideas! is there any other way to do that. Note, I must do it from within .net usercontrol not xslt. Thanks in advace
EDIT: I am sorry guys, this is not the right solution, please see Lee's next solution and my little tweeks after his.
Ah, I guess I was blind... first of course there is no $currentPage and instead I should use a **dot .** and, preceding-siblings should be preceding-sibling without **s** at the end.
So my working code is:
******* EDIT: This wasn't the right solution *********
MOthman, you might want to double-check your solution... the XPath used in the "Node.GetNodeByXpath" method is applied to the entire content node tree (e.g. the XML cache) ... which means that if you use "." (dot) - which implies the "current" node, e.g. the root node, then using the "//" (double-slash) which means get ALL descendant nodes. There is still no context to the current page you are on.
Try my solution above, see how that works for you?
Lee, many thanks for your solution, with a few small tweeks I managed to get it working. I used your code but instead of decendant, we should use decendant-or-self, and sibling without s at the end (perhaps, it was my fault )
The working code is
var sibling = Node.GetNodeByXpath(string.Concat("descendant-or-self::*[@isDoc and @id = ", _currentNode.Id, "]/preceding-sibling::* [@isDoc][1]"));
Response.Redirect to next preceding sibling with umbraco.NodeFactory GetNodeByXpath from .net Usercontrol
I want to redirect customers from one page to its first preceding sibling from .NET usercontrol. This is my code but I get exception "$currentPage/preceding-siblings::* [@isDoc][1] **has an invalid token**."
Node sibling = Node.GetNodeByXpath(@"$currentPage/preceding-siblings::* [@isDoc][1]");
if (sibling != null)
Response.Redirect(umbraco.library.NiceUrl(sibling.Id));
As of course currentPage is not a defined parameter in .net usercontrol, I thought about removing it, so, I wrote this
Node sibling = Node.GetNodeByXpath(@"/preceding-siblings::* [@isDoc][1]");
if (sibling != null)
Response.Redirect(umbraco.library.NiceUrl(sibling.Id));
I tried more ways, nothing works and I don't want to go with too long solutions. I can't figure out what is wrong in my code, any ideas! is there any other way to do that. Note, I must do it from within .net usercontrol not xslt. Thanks in advace
EDIT: I am sorry guys, this is not the right solution, please see Lee's next solution and my little tweeks after his.
Ah, I guess I was blind... first of course there is no $currentPage and instead I should use a **dot .** and, preceding-siblings should be preceding-sibling without **s** at the end.
So my working code is:
******* EDIT: This wasn't the right solution *********
Hi MOthman,
Unfortunately the "Node.GetNodeByXpath" method has no context of the "$currentPage" parameter ... (that only works within XSLT).
Instead, try something like this...
You'll get the current node/page, then use its Id to create the approprate XPath expression to get the first preceding-sibling.
Cheers, Lee.
MOthman, you might want to double-check your solution... the XPath used in the "Node.GetNodeByXpath" method is applied to the entire content node tree (e.g. the XML cache) ... which means that if you use "." (dot) - which implies the "current" node, e.g. the root node, then using the "//" (double-slash) which means get ALL descendant nodes. There is still no context to the current page you are on.
Try my solution above, see how that works for you?
Cheers, Lee.
Lee, I am trying to remove my solution but I couldn't, I realised it doesn't work properly
No worries MOthman, it's a restriction of the forum. :-)
Cheers, Lee.
Lee, many thanks for your solution, with a few small tweeks I managed to get it working. I used your code but instead of decendant, we should use decendant-or-self, and sibling without s at the end (perhaps, it was my fault )
The working code is
This is my first time to post on Umbraco forum but not the last :)
This solution credit should go to Lee, cheers
Hi MOthman,
Sorry about the typos... that's what I get for writing code off the top of my head! ;-)
Glad that you got it sorted in the end. Welcome to the Umbraco community!
Cheers, Lee.
is working on a reply...