How do you get the asp:Menu to follow the url provided in the Web.sitemap?
Asked Answered
D

1

8

I have a simple asp:menu-item that uses the Web.sitemap to get the menu items. The page will postback but fails to get the page associated to the clicked item. I will mention that the navigation bar code is within the masterpage file.

<div>
  <asp:SiteMapDataSource ID="SiteMapDataSource1"  ShowStartingNode="false" runat="server" />
  <asp:Menu ID="Menu1" Orientation="horizontal"  runat="server" BackColor="#a0a080" DataSourceID="SiteMapDataSource1"
      DynamicHorizontalOffset="2" Font-Names="Verdana" Font-Size="0.8em" ForeColor="#a00000"
      StaticSubMenuIndent="10px" Style="z-index: 2; left: 390px; position: absolute;
      top: 281px" Height="20px" Width="311px">
      <StaticSelectedStyle BackColor="#a0a080" />
      <StaticMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
      <DynamicHoverStyle BackColor="#a0a080" ForeColor="White" />
      <DynamicMenuStyle BackColor="#a0a080" />
      <DynamicSelectedStyle BackColor="#a0a080" />
      <DynamicMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
      <DataBindings>
          <asp:MenuItemBinding DataMember="SiteMapNode" EnabledField="Title" TextField="Title" />
      </DataBindings>
      <StaticHoverStyle BackColor="#666666" ForeColor="White" />
  </asp:Menu>
</div>    

<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >  
  <siteMapNode url="" title=""  description="">  
    <siteMapNode title="Home"  description="Zombie (be)Warehouse" url="index.aspx" />  
    <siteMapNode title="Armor" description="Anti-Zombie Armor" url="Armor.aspx" />  
    <siteMapNode title="Weapons" description="Anti-Zombie Weapons" url="Weapons.aspx" />  
    <siteMapNode title="Manuals" description="Survival Manuals" url="Manuals.aspx" />  
    <siteMapNode title="Sustenance" description="Prepared food for survival" url="Sustenance.aspx" />  
    <siteMapNode title="Contacts"  description="Contact Us"  url="Contacts.aspx" />  
    <siteMapNode title="About" description="About Zombie (be)Warehouse" url="About.aspx" />  
  </siteMapNode>  
</siteMap>

Update: The problem is being found in the DataBindings section of the menu item. Notice the line:

<asp:MenuItemBinding DataMember="SiteMapNode" EnabledField="Title" Text="Title" />

The Text="Title" sets the menu's displayed text from the Web.sitemap's text field. I noticed that the MenuItemBinding item had a field called NavigateUrlField.

So to solve this issue, you simple need to change/add to the asp:MenuItemBinding

<asp:MenuItemBinding DataMember="SiteMapNode" NavigateUrlField="url" EnabledField="Title" TextField="Title" />
Dewees answered 17/9, 2008 at 5:48 Comment(1)
So it sounds as though you issue is resolved? If so, nice work!Jackinthebox
P
0

You need to add the NavigateUrlField field to the MenuItemBinding like this <asp:MenuItemBinding DataMember="SiteMapNode" EnabledField="Title" TextField="Title" NavigateUrlField="url"/>

Potoroo answered 26/5, 2019 at 13:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.