[RESOLVED]How to use Sitemappath control to add breadcrumbs in Master Page of a website?

I am trying to add breadcrumbs on my web pages for easy navigation. For this I am using SiteMapPath Control of Asp.Net and along with this I have also made a breadcrumb.Sitemap file which list all the pages. But While implementing the sitemappath in my master
page, I am getting a generic error. I am not able to understand why is this happening?
This is the basic structure of my aspx page-

<div id="menu-pt">
<div class="hm"><a href="Page1.aspx" class="active">Home</a></div>
<div id="nav">
<ul id="nav" name="nav">
            	<li><a href="Page2.aspx">Page2</a></li>
                <div class="saparation"></div>
                <li><a href="Page3.aspx">Page3</a></li>
                <div class="saparation"></div>
             <li> <a href="Page4.aspx">Page4</a></li>
			<div class="saparation"></div>
            <li><a href="#">Pages</a>
            <div id ="Ul2" runat="server">
                <ul id="sub-nav" >
                <li><a href="Page5.aspx">Page5</a></li>
         		<li><a href="Page6.aspx">Page6</a></li>
          		<li><a href="Page7.aspx">Page7</a></li>
          		<li><a href="Page8.aspx">Page8</a></li>
            </ul>
            </div>
             <div id ="Ul1" runat="server">
             <ul id="sub-nav" >
             
                <li><a href="Page9.aspx">Page9</a></li>
         		<li><a href="Page10.aspx">Page10</a></li>
         		<li><a href="Page11.aspx">Page11</a></li>
          		<li><a href="Page12.aspx">Page12</a></li>
          		<li><a href="Page13.aspx">Page13</a></li>
            </ul>
            </div>
                </li>          
		   </ul>
</div>
</div>

<li>Page5,6,7,8.aspx pages is for all users. And <li>Page9,10,11,12,13.aspx pages are for logged in user.
And My breadcrumb.sitemap file is-

<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
    <siteMapNode url="Page1.aspx" title="Home"  description="Page1">
        <siteMapNode url="Page2.aspx" title="Page2"  description="Page2" />
        <siteMapNode url="Page3.aspx" title="Page3"  description="Page3" />
      <siteMapNode url="Page4.aspx" title="Page4"  description="Page4" />
      <siteMapNode url="" title="Pages"  description="">
        <siteMapNode url="Page5.aspx" title="Page5"  description="Page5" />
        <siteMapNode url="Page6.aspx" title="Page6"  description="Page6" />
        <siteMapNode url="Page7.aspx" title="Page7"  description="Page7" />
        <siteMapNode url="Page8.aspx" title="Page8"  description="Page8" />
        <siteMapNode url="Page9.aspx" title="Page9"  description="Page9" />
        <siteMapNode url="Page10.aspx" title="Page10"  description="Page10" />
        <siteMapNode url="Page11.aspx" title="Page11"  description="Page11" />
        <siteMapNode url="Page12.aspx" title="Page12"  description="Page12" />
        <siteMapNode url="Page13.aspx" title="Page13"  description="Page13" />
      </siteMapNode>
    </siteMapNode>
</siteMap>

Also I have placed a sitemappath control on my aspx page-

<asp:SiteMapPath ID="SiteMapPath1" runat="server"></asp:SiteMapPath>

Please guide me where I am doing wrong. I read few articles and it says that this much of step is enough for adding breadcrumbs on every pages of a web site.

Please Guide me where I am doing Wrong?

Hi,

For this situation, you must set the siteMapNode url property to the correct path of the the aspx page, and put it in the root of the project. For more detailed information, you could refer to the following links:

http://www.aspdotnet-suresh.com/2012/09/sitemap-navigation-control-example-in.html

http://msdn.microsoft.com/en-us/library/x20z8c51.aspx

Besides, below is a simple example for your reference:

1. Create a folder in the project named SiteMapNavigation;

2. Within the above folder create master page SitemapNavigation.Master and pages with the master page, Home.aspx, Careers.aspx, Jobs.aspx, ContactUs.aspx;

SitemapNavigation.Master:

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="SitemapNavigation.master.cs" Inherits="Testing.SiteMapNavigation.SitemapNavigation" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <asp:ContentPlaceHolder ID="head" runat="server">
    </asp:ContentPlaceHolder>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager" runat="server"></asp:ScriptManager>
        <div style="background-color:red">fdssdfdfdsfs</div>
                       <br />
        <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />
        <asp:TreeView ID="TreeView1" runat="server" DataSourceId="SiteMapDataSource1" />
 
        
        <asp:SiteMapPath ID="SiteMap1" runat="server"></asp:SiteMapPath><br/><br/>

        <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
        
        </asp:ContentPlaceHolder>
    </div>
    </form>
</body>
</html>

3. Create the Web.sitemap file:

<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
  <siteMapNode url="~/SiteMapNavigation/Home" title="Home"  description="Home Page">
    <siteMapNode url="~/SiteMapNavigation/Careers.aspx" title="Careers"  description="Careers Page" >
    <siteMapNode url="~/SiteMapNavigation/Jobs.aspx" title="Jobs"  description="Jobs Page" />
    </siteMapNode>
    <siteMapNode url="~/SiteMapNavigation/ContactUs.aspx" title="Contact"  description="ContacUs Page" />
  </siteMapNode>
</siteMap>

If the above information couldn’t help, please tell us the error message when you encounter the issue.

Regards

Hello Sir,
Thanks a lot for explaining me the whole process in detail.
Sir, I have a doubt, I want to understand that-
1. What happens If I don’t use Menu Control of asp.net in my master page.
2. What if I make my menu’s hardcoded i.e. by using <ul><li> tags. In this case will the sitemappath will work, as it reads automatically the sitemap nodes listed in Web.sitemap file.
Actually I am not using Asp.net menu control in my master page. Instead of that I have made my own menu’s using <ul><li> tags.
And one more thing you have used update panel in your example. I want to understand why you have used update panel? Does it make any change?
If it is necessary to use update panel to handle the page refresh. Then in my example where I should place it? Actually sir, I am very curious to understand these things in details.
Hope you will clear all my doubts.

Hi,

First of all, it’s my fault that I didn’t remove the unrelated codes with this issue. In order to test another issue, I added the update panel to the page and forgot to remove it.

ashish_sourav11

What happens If I don’t use Menu Control of asp.net in my master page.

If you don’t want to use the menu control or treeview control in the page, the page would not display the whole path for the user, and when the user navigate to a specific page, he only can see the navigate path not the whole website pages path. For example:

http://asp-net-example.blogspot.com/2008/10/sitemappath-example-how-to-use.html

If you make the menu’s hardcoded, then the user can see the whole pages within your site, however, he can’t browse the page by simply click on the tags. If you use the tree view or menu control, you can browse to the specific page by clicking on the corresponding node
within control, it’s really useful and simple.

Besides, the sitemapdatasource control automatically works with the application’s web.sitemap file. It allow to bind the hierarchical sitemap data with hierarchical web server control such as sitemappath, treeview, menu and so on. For detailed information,
please refer to:

http://www.codecomplete4u.com/asp-net-navigation-sitemap-part-2/

Regards

Thanks a ton Sir Smile
Thanks for explaining me everything so beautifully.
Actually Since I am using three different masterpages that is why I was getting that error.
Sir, Now what I did I only listed those pages in which my first master page was used, and I was able to implement breadcrumbs on those pages.
So, I guess I have to make three different Web.Sitemap Pages? Am I right Sir. . .?
Please clear this confusion of mine.

Hi,

 

By default, ASP.NET site navigation works with an XML file that is named Web.sitemap that describes the hierarchy of the Web site. However, you might want to use more than one site-map file or site-map
provider to describe the navigation structure of a complete Web site.

 

To configure multiple site maps for a single site, you start with a site map in the root of the application. Configure the root provider as the default site-map provider in the Web.config file. Then
link to child site maps or providers by referencing them in a
SiteMapNode
object.

 

http://msdn.microsoft.com/en-us/library/ms178426(v=vs.100).aspx

http://www.codeproject.com/Articles/26962/Using-More-than-One-SiteMapPath-in-a-Single-Web-Pr

Regards

Leave a Reply