Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Web applications that you develop will have multiple pages interconnected with each other in some
fashion. You need to have a navigation system in place which can help the end user to successfully work
through your application. There is no standard mechanism which offers well-defined navigation system for
the web application in ASP.NET 1.x. Only known method for building navigation within web application is to
fill the pages with hyperlinks. Problem arises when you move pages around or change page names.
Hyperlinks don't work phew!! As site grows and new pages are added, it will be a nightmare for the
developer to manage all the links in the application.
ASP.NET 2.0 eliminates this problems with a built in site navigation feature which provides a consistent
way for the user to navigate your website. The new site navigation system allows defining all the links at a
central location file usually an XML file and display those links in lists or navigation menus in each required
page using navigation-based server controls.
Different ways to implement Site Navigation in ASP.NET 2.0
Site maps: Site maps are XML files which describes the logical structure of your web application. We can
use it to define the layout of all pages in application and how they relate to one another. You can add or
remove links/pages to your site map there by managing navigation of website effectively. Site maps are
defined with .sitemap extension. You can interact with site maps in variety of ways. You can use sitemap
class for programmatic access to site map file. You can also use new SiteMapDataSource control to help
bind the information in the site map file to new navigation server controls provided by ASP.NET 2.0
<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
<siteMapNode url="Default.aspx" title="Home" description="Home Page">
<siteMapNode url="News.aspx" title="News" description="The Latest News" >
<siteMapNode title ="U.S" description ="U.S News" url ="News.aspx?cat=us" />
<siteMapNode title ="UK" description ="UK News" url ="News.aspx?cat=uk" />
<siteMapNode title="Asia" description ="Asia News" url="News.aspx?cat=asia" />
</siteMapNode>
<siteMapNode url="finance.aspx" title="Finance" description="The Latest Finance" >
<siteMapNode title="NASDAQ" description="NASDAQ" url="finance.aspx?cat=nasdaq" />
<siteMapNode title="NY" description ="Newyork" url="finance.aspx?cat=ny"/>
<siteMapNode title ="HONGKONG" description ="HongKong" url="finance.aspx?cat=hongkong"/>
</siteMapNode>
<siteMapNode url="weather.aspx" description ="Latest Weather" title="Weather">
<siteMapNode title="NYC" description="NewYorkCity Weather" url ="weather.aspx?cat=nyc"/>
<siteMapNode title="Chicago" description ="Chicago Weather" url="weather.aspx?cat=chicago" />
</siteMapNode>
</siteMapNode >
</siteMap>
The SiteMapPath control creates navigation mechanism which is generally referred to as breadcrumb
navigation. This is a linear path defining where the user is currently located in navigation structure. It
usually helps end user to know his location in relation to the rest of the site.
We have already seen the structure of sitemap file. We will use the same sitemap for our example. The
SiteMapPath server control is so easy to use that you can simply drag and drop the server control onto
any page and it shows breadcrumb navigation for that page.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="AsiaNews.aspx.cs" Inherits="AsiaNews"
%>
</div>
</form>
</body>
</html>
SiteMapPath Server control listing
In the above sample, I have added SiteMapPath control to AsiaNews.aspx and you can see in output when
you open AsiaNews.aspx, you will observe that this page belongs to News section of the site which is turn
belongs to Home section of website.
The SiteMapPath control creates breadcrumb navigation with very little effort on your part.
PathDirection Property
This property changes the direction of the links generated in the
output. Possible settings for this property are RootToCurrent
and CurrentToRoot. In the above example, I have used default
RootToCurrent setting. If we change the setting to CurrentToRoot
you will the output as shown below. I think you got the difference.
Output listing for Menu Control using SiteMapDataSource control using sitemap xml file
ASP.NET 2.0 provides powerful navigation mechanisms. The core of the new navigation model is the ability
to represent the navigation structure in an xml file which can then used by navigation controls such as
SiteMapPath controls. You can design navigation structure for your application without writing single piece
of code.
If you are professional software developer, you have deadlines and your time is your most important
resource. With standard ASP.NET Menu server control you can do a lot of things, but everything will take
time. If you suppose that you will lose too much time in menu issues, it will be better to get some more
advanced solution like ExpertMenu. With this control you can save a lot of programming (and debugging)
hours and get nice looking, feature rich solution, already well tested in many other sites worldwide.