Search

Monday, December 22, 2014
0 comments

SiteMap Path example in ASP.NET

1:00 AMMonday, December 22, 2014
Using the SiteMap Path class you can navigate a website. It displays a set of Text or images Hyperlinks. Inheritance hierarchy of SiteMapPath class are:
System.Object
    System.Web.UI.Control
      System.Web.UI.WebControls.WebControl
         System.Web.UI.WebControls.CompositeControl
            System.Web.UI.WebControls.SiteMapPath

Lets take an simple example of SiteMap Path 

To create Web.Sitemap, right click the website name. A context menu appears. Select the Add New Item option from the context menu. The Add New Item dialog box appear. Select Site Map from the option available. This will create a new web.sitemap file in the website.

 The Web.sitemap file consists of navigational details for an application. You can set the title, URL, and other information for each page by using the Web.sitemap file. code, copy and paste into your sitemap file.

Article : How to use Menu Control in ASP.NET

Video : A simple video contain how to use menu and sitemap file

  <?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
    <siteMapNode url="~/Default.aspx" title="Home Page"  description="">
        <siteMapNode url="~/About.aspx" title="About"  description="" />
        <siteMapNode url="~/contact.aspx" title="contact us"  description="" />
    </siteMapNode>
</siteMap>


After that Add a master page and three web form(Default.aspx, About.aspx, contact.aspx)  into the website folder. Here we take ASP.NET website , which is contain default asp.net template. After Completed your sitemap file you can add sitemap path control to the master page.

Note : Add SiteMap Path control into the master page after navigation control

Master page source code , where your sitemap path control exists

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="Site.master.cs" Inherits="SiteMaster" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head runat="server">
    <title></title>
    <link href="~/Styles/Site.css" rel="stylesheet" type="text/css" />
    <asp:ContentPlaceHolder ID="HeadContent" runat="server">
    </asp:ContentPlaceHolder>
</head>
<body>
    <form runat="server">
    <div class="page">
        <div class="header">
            <div class="title">
                <h1>
                    My ASP.NET Application
                </h1>
            </div>
            <div class="loginDisplay">
                <asp:LoginView ID="HeadLoginView" runat="server" EnableViewState="false">
                    <AnonymousTemplate>
                        [ <a href="~/Account/Login.aspx" ID="HeadLoginStatus" runat="server">Log In</a> ]
                    </AnonymousTemplate>
                    <LoggedInTemplate>
                        Welcome <span class="bold"><asp:LoginName ID="HeadLoginName" runat="server" /></span>!
                        [ <asp:LoginStatus ID="HeadLoginStatus" runat="server" LogoutAction="Redirect" LogoutText="Log Out" LogoutPageUrl="~/"/> ]
                    </LoggedInTemplate>
                </asp:LoginView>
            </div>
            <div class="clear hideSkiplink">
                <asp:Menu ID="NavigationMenu" runat="server" CssClass="menu" EnableViewState="false" IncludeStyleBlock="false" Orientation="Horizontal">
                    <Items>
                        <asp:MenuItem NavigateUrl="~/Default.aspx" Text="Home"/>
                        <asp:MenuItem NavigateUrl="~/About.aspx" Text="About"/>
                    </Items>
                </asp:Menu>
            </div>
        </div>
        <div class="main">
            <asp:SiteMapPath ID="SiteMapPath2" runat="server">
            </asp:SiteMapPath>
            <br />
            <asp:ContentPlaceHolder ID="MainContent" runat="server"/>
        </div>
        <div class="clear">
        </div>
    </div>
    <div class="footer">
        
    </div>
    </form>
</body>
</html>

Code Generate the following output

SiteMap Path in ASP.NET

Protected by Copyscape Online Copyright Protection Software

0 comments :

Post a Comment

 
Toggle Footer
Top