views:

98

answers:

1

I'm trying to build a dynamic site map on my site using SiteMapPath. Should be like this: Home > Products > %product_name% > Prices where %product_name% is set dynamically in the runtime, depends on user's choice.

I've read many articles on the theme and choose this http://harriyott.com/2007/03/adding-dynamic-nodes-to-aspnet-site.aspx. It dynamically changes the Web.sitemap XML file. The problem is that it still builds the sitemap only once in the beginning and then uses it on each page.

How can i make it to rebuild on each loaded page?

A: 

Hello,

try this :

right click on your project "add new item" then choose "Site Map", it will have an XML structure it will look like this :

< ?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="">

     < siteMapNode url="~/the page URL" title="Products"  description="" >

         < siteMapNode url="~/the page URL" title=" %product_name%"  description="" >

             < siteMapNode url="~/the page URL" title="Prices"  description="" />

         < /siteMapNode >

     < /siteMapNode >

   < /siteMapNode >

 < sitemap>

** adding description for each node is optional.

now you need to place it where you want , so you add this code in the HTML side of the page:

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

< CurrentNodeStyle CssClass="Some class" />

< PathSeparatorTemplate>

  < img runat="server" alt="" src="an image to separate between nodes" height="5" width="5" />

< /PathSeparatorTemplate>


of course you have two pages , one for product , and one for prices.

to assign Tile dynamically for some node in the SiteMap add this code in the Prices Page:

1) in the page load :

SiteMap.SiteMapResolve += new SiteMapResolveEventHandler(SiteMap_SiteMapResolve);

2) add this function in the same page (prices page) :

 SiteMapNode SiteMap_SiteMapResolve(object sender, SiteMapResolveEventArgs e)
{
    SiteMapNode currentNode = SiteMap.CurrentNode.Clone(true);
    SiteMapNode tempNode = currentNode;

    tempNode.ParentNode.Title = "Change the Product name";
    tempNode.ParentNode.Url = "Change the Product url";

    return currentNode;
}

as you can see you can manipulated the parent Node as you want , change the title , the url , i think yo u want to change the url too , maybe "product.aspx?ID=blah"

Arrabi
in that case, the %product_name% value is constant, and i need it to be set in the runtime, when Product.aspx loads and the selected product is known
GaGar1n
I updated My answer , please check it
Arrabi