SiteMapPath Class

Displays a set of text or image hyperlinks that enable users to more easily navigate a Web site, while taking a minimal amount of page space.

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)

[AspNetHostingPermissionAttribute(SecurityAction::LinkDemand, Level = AspNetHostingPermissionLevel::Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction::InheritanceDemand, Level = AspNetHostingPermissionLevel::Minimal)]
public ref class SiteMapPath : public CompositeControl
<asp:SiteMapPath />

The SiteMapPath control is a site navigation control that reflects data provided by the SiteMap object. It provides a space-saving way to easily navigate a site and serves as a point of reference for where the currently displayed page is within a site. This type of control is commonly called a breadcrumb, or eyebrow, because it displays a hierarchical path of hyperlinked page names that provides an escape up the hierarchy of pages from the current location. SiteMapDataSource. The SiteMapPath is useful for sites that have deep hierarchical page structures, but where a TreeView or Menu might require too much space on a page.

The SiteMapPath control works directly with your Web site's site map data. If you use it on a page that is not represented in your site map, it will not be displayed. For more information about site maps, see ASP.NET Site Navigation Overview.

The SiteMapPath is made up of nodes. Each element in the path is called a node and is represented by a SiteMapNodeItem object. The node that anchors the path and represents the base of the hierarchical tree is called the root node. The node that represents the currently displayed page is the current node. Any other node between the current node and root node is a parent node. The following table describes the three different node types.

Node type

Description

root

A node that anchors a hierarchical set of nodes.

parent

A node that has one or more child nodes, but is not the current node.

current

A node that represents the currently displayed page.

Each node displayed by a SiteMapPath is a HyperLink or Literal control that you can apply a template or style to. The templates and styles are applied to nodes according to two rules of precedence:

  • If a template is defined for a node, it overrides any style defined for the node.

  • Templates and styles that are specific to types of nodes override general templates and styles defined for all nodes.

The NodeStyle and NodeTemplate properties are applied to all nodes, regardless of their node type. If both these properties are defined, the NodeTemplate takes precedence.

The CurrentNodeTemplate and CurrentNodeStyle properties are applied to nodes that represent the currently displayed page. If a NodeTemplate is defined in addition to the CurrentNodeTemplate, it is ignored. If a NodeStyle is defined in addition to the CurrentNodeStyle, it is merged with the CurrentNodeStyle to create a merged style. This merged style uses all the elements of the CurrentNodeStyle, plus any additional elements of the NodeStyle that do not conflict with the CurrentNodeStyle.

The RootNodeTemplate and RootNodeStyle properties are applied to the node that represents the root of the site navigation hierarchy. If a NodeTemplate is defined in addition to the RootNodeTemplate, it is ignored. If a NodeStyle is defined in addition to the RootNodeStyle, it is merged with the RootNodeStyle to create a merged style. This merged style uses all the elements of the RootNodeStyle, plus any additional elements of the NodeStyle that did not conflict with the CurrentNodeStyle. Finally, if the currently displayed page is the root page of the site, the RootNodeTemplate and RootNodeStyle are used instead of the CurrentNodeTemplate or CurrentNodeStyle.

The SiteMapPath control uses the site map provider identified by the SiteMapProvider property as its data source for site navigation information. If no provider is specified, it uses the default provider for the site, identified in the SiteMap::Provider property. Typically, this is an instance of the default site map provider for ASP.NET, the XmlSiteMapProvider. If the SiteMapPath control is used within a site but no site map provider is configured, the control throws an HttpException exception.

The SiteMapPath control also provides events that you can program against. This allows you to run a custom routine whenever an event occurs. The following table lists the events supported by the SiteMapPath control.

Event

Description

ItemCreated

Occurs when the SiteMapPath control first creates a SiteMapNodeItem and associates it with a SiteMapNode.

ItemDataBound

Occurs when a SiteMapNodeItem is bound to site map data contained by the SiteMapNode.

Classes that derive from SiteMapPath override the InitializeItem method to customize the SiteMapNodeItem controls contained by the navigation control. For complete control over the way SiteMapNodeItem objects are created and added to the SiteMapPath, derived classes override the CreateControlHierarchy method.

Accessibility

The markup rendered by default for this control might not conform to accessibility standards such as the Web Content Accessibility Guidelines 1.0 (WCAG) priority 1 guidelines. For details about accessibility support for this control, see ASP.NET Controls and Accessibility.

TopicLocation
How to: Programmatically Enumerate Site-Map NodesBuilding ASP .NET Web Applications
How to: Configure Multiple Site Maps and Site-Map ProvidersBuilding ASP .NET Web Applications
How to: Filter the Nodes Retrieved by SiteMapDataSource Web Server ControlsBuilding ASP .NET Web Applications
How to: Programmatically Modify Site-Map Nodes in MemoryBuilding ASP .NET Web Applications
How to: Localize Site-Map DataBuilding ASP .NET Web Applications
How to: Customize the Appearance of SiteMapPath Web Server ControlsBuilding ASP .NET Web Applications
How to: Display Site-Map Data in Non-Hierarchical Web Server ControlsBuilding ASP .NET Web Applications
How to: Add Simple Site NavigationBuilding ASP .NET Web Applications
How to: Implement ASP.NET Site-Map ProvidersBuilding ASP .NET Web Applications
How to: Programmatically Enumerate Site-Map NodesBuilding ASP .NET Web Applications
How to: Configure Multiple Site Maps and Site-Map ProvidersBuilding ASP .NET Web Applications
How to: Filter the Nodes Retrieved by SiteMapDataSource Web Server ControlsBuilding ASP .NET Web Applications
How to: Programmatically Modify Site-Map Nodes in MemoryBuilding ASP .NET Web Applications
How to: Localize Site-Map DataBuilding ASP .NET Web Applications
How to: Customize the Appearance of SiteMapPath Web Server ControlsBuilding ASP .NET Web Applications
How to: Display Site-Map Data in Non-Hierarchical Web Server ControlsBuilding ASP .NET Web Applications
How to: Add Simple Site NavigationBuilding ASP .NET Web Applications
How to: Implement ASP.NET Site-Map ProvidersBuilding ASP .NET Web Applications
Walkthrough: Adding Site Navigation to a Web SiteBuilding ASP .NET Web Applications in Visual Studio
How to: Add Simple Site NavigationBuilding ASP .NET Web Applications in Visual Studio

The following code example uses a SiteMapPath control declaratively in a Web Forms page. This example demonstrates some of the rules of precedence that govern the order with which templates and styles are applied to SiteMapPath nodes.

No code example is currently available or this language may not be supported.

The previous example uses the default site map provider and a Web.sitemap file with the following structure.

<siteMap>
  <siteMapNode title="WebForm1" description="WebForm1" url="WebForm1.aspx" >
    <siteMapNode title="WebForm2" description="WebForm2" url="WebForm2.aspx"/>
  </siteMapNode>
</siteMap>

The following code example demonstrates extends the SiteMapPath control and adds new functionality to it by overriding the InitializeItem method. The DropDownSiteMapPath control adds a DropDownList after the current node, to enable easy navigation to pages that are child nodes of the current page. This example demonstrates how to work with SiteMapNodeItem objects, including checking their SiteMapNodeItemType and calling the OnItemCreated method after the items are created.

No code example is currently available or this language may not be supported.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft