I\'m extremely unfamiliar with both .NET and VB.NET and can\'t quite figure out how to do this. Say I have code like this:
While a little involved, this is a solution that actually removes the spans and renders a clean list.
First, get rid of those excess spans by modifying the SiteMapPath
. I have derived a class NakedSiteMapPath
that does this. It still allows the usage of explicit spans in templates, if needed:
///
/// A SiteMapPath, that does not render span elements.
///
///
/// To still allow explizit spans inside the node templates, immediately prefix the opening and closing span elements
/// with the literal
/// prefix "" (without the double quotes)
/// Example:
///
///
///
///
/// Those spans (opening and closing) will be kept, but the prefix removed in the rendered output.
///
///
/// The MSDN doc has a nice example about a customized breadcrumb with a dropdown menu here:
/// https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.sitemappath%28v=vs.110%29.aspx
///
[AspNetHostingPermission(SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Minimal)]
[ToolboxData("<{0}:NakedSiteMapPath runat=server>{0}:NakedSiteMapPath>")]
public class NakedSiteMapPath : SiteMapPath {
///
/// Outputs server control content to a provided object and stores
/// tracing information about the control if tracing is enabled.
///
/// The object that receives the control content.
public override void RenderControl(HtmlTextWriter writer) {
//Render to a local string, then remove all unnecessary spans
StringBuilder myStringBuilder = new StringBuilder();
TextWriter myTextWriter = new StringWriter(myStringBuilder);
HtmlTextWriter myWriter = new HtmlTextWriter(myTextWriter);
base.RenderControl(myWriter);
string html = myStringBuilder.ToString();
//Remove all spans, except those opening and closing spans wich have been marked with the literal comment ""
const string matchOpenExceptSkipPrefix = @"(?)";
const string matchCloseExceptSkipPrefix = @"(?)";
html = Regex.Replace(html, matchOpenExceptSkipPrefix, String.Empty);
html = Regex.Replace(html, matchCloseExceptSkipPrefix, String.Empty);
html = html.Replace(@"", String.Empty);
//finally, write the naked html out.
writer.Write(html);
}
}
With that, the spans are gone. To have custom links, like the li
elements, you will need to use the templates, as others already have proposed. Here's an example ASPX page part with the NakedSiteMapPath
: