RSS 2.0
# Tuesday, April 29, 2008

Jeff Prosise made a nice blog entry about hiding the root node in the SiteMapPath-control. Some people, like myself, experienced an issue when the current node and the root node ar actually the same. Somehow the check that should avoid that issue fails. I believe because the current node is in fact a clone of the current node, and as such not equal to the current node (i.e. root node) itself. To get around this, I have changed the code somewhat to do the check on the actual nodes. The body of the HideRootNode-method is now as follows:

// Return root node in case this is the root.
if(SiteMap.RootNode == SiteMap.CurrentNode) return SiteMap.CurrentNode;

// This is not the root node, so rebuild path without root.
SiteMapNode node = SiteMap.CurrentNode.Clone();
SiteMapNode current = node;

while (node.ParentNode != SiteMapNode.RootNode)
{
    node.ParentNode = node.ParentNode.Clone();
    node = node.ParentNode;
}
node.ParentNode = null;
return current;

Thanks to Jeff for his original insight. It saved me a lot of time.

Tuesday, April 29, 2008 5:19:51 PM (W. Europe Daylight Time, UTC+02:00)  #    Comments [3] -
ASP.NET | English
Tuesday, June 10, 2008 10:24:37 AM (W. Europe Daylight Time, UTC+02:00)
Your code does not compile. SiteMapNode.CurrentNode doesn't exist. I guess it should be SiteMap.CurrentNode.

Also the variable named "root" isn't declared in your code...
Saturday, July 19, 2008 8:13:57 PM (W. Europe Daylight Time, UTC+02:00)
Thanks for your comments Leon, I've fixed both.
Wednesday, November 12, 2008 4:26:51 AM (W. Europe Standard Time, UTC+01:00)
Hi

I am pretty new to ASP (so please excuse my silly question). It sounds like this is for my problem exactly, I some code in the RootNodeTemplate that I want displayed, even when RootNode and CurrentNode are the same node.

Where is this code meant to go? I'm using ASP.NET and C#.NET

-- Sophia
All comments require the approval of the site owner before being displayed.
Name
E-mail
Home page

Comment (Some html is allowed: a@href@title, strike) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.  

Enter the code shown (prevents robots):

Live Comment Preview
Sign In

Archive
<February 2012>
SunMonTueWedThuFriSat
2930311234
567891011
12131415161718
19202122232425
26272829123
45678910
About
This is the blog of Michiel van Otegem, a Senior Software Architect with Sogeti Netherlands, and author of several books and numerous articles on (ASP).NET, XML, and related technologies.
Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2012
Michiel van Otegem
All Content © 2012, Michiel van Otegem
DasBlog theme 'Business' created by Christoph De Baene (delarou)