菜单控件的意外渲染

时间:2012-01-15 16:11:23

标签: asp.net

我创建了导航菜单,它从站点地图源获取数据,但是当从任何客户端而不是服务器打开它时,我发现它无法正确渲染并添加了额外的节点,如下所示:

<a class="level1 staticMenuItemStyle static" href="#" onclick="__doPostBack('ctl00$NavigationMenu','')" tabindex="-1"></a>

这里是我的代码片段:

//sitemap file
    <?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
  <siteMapNode>
    <siteMapNode url="~/home.aspx" title="Home" description="Home" accesskey="H" />
    <siteMapNode url="~/MemberPages/PLCInfoPage.aspx" title="Resource Info"
                   description="ResourceInfo" accesskey="P" />
      <siteMapNode url="~/MemberPages/RequestReservation.aspx" title="Request Reservation"
                     description="RequestReservation" accesskey="E" />
      <siteMapNode url="~/MemberPages/ExtendReservationPage.aspx" title="Extend Reservation"
                     description="ExtendReservation" accesskey="E" />
      <siteMapNode url="~/MemberPages/InitiateSession.aspx" title="Initiate Session"
                 description="InitiateSession" accesskey="N"/>

      <siteMapNode url="~/MemberPages/SearchPage.aspx" title="Search"
               description="SearchPage" accesskey="U"/>

    <siteMapNode url="~/AdminPages/AdminHome.aspx" title="Admin"
               description="Administration" requiresResourceType="Admin" accesskey="U">
      <siteMapNode url="~/AdminPages/ManagAdmiistrators.aspx" title="Manage Accounts"
                  description="Manage Accounts"
                  accesskey="S" />
      <siteMapNode url="~/AdminPages/ResourcePropertiesPage.aspx" title="Manage Resource Properities"
                  description="Manage Resource Properities"
                  accesskey="B" />
      <siteMapNode url="~/AdminPages/ManageLocations.aspx" title="Manage Locations and Labs"
               description="Manage Locations and Labs"
               accesskey="B" />
      <siteMapNode url="~/AdminPages/PLCManagepage.aspx" title="Manage Resources"
                 description="Manage Resources"
                 accesskey="B" />
      <siteMapNode url="~/AdminPages/CheckReservations.aspx" title="Check Reservations"
                   description="Check Reservations"
                   accesskey="B" />
      <siteMapNode url="~/MemberPages/feedbackReport.aspx" title="Show feedback"
                     description="Show feedback"
                     accesskey="B" />
      <siteMapNode url="~/AdminPages/messagesPage.aspx" title="Add Messages"
                     description="Add Messages"
                     accesskey="B" />
    </siteMapNode>
    <siteMapNode url="~~/Help.aspx" title="Help"
                     description="Help"
                     accesskey="B" />
  </siteMapNode>
</siteMap>

//来自母版页的片段,其中存在菜单

          <div class="clear hideSkiplink">   
               <asp:menu id="NavigationMenu"   CssClass="menu" 
        staticdisplaylevels="2" DynamicHorizontalOffset="1"
        staticsubmenuindent="1px" MaximumDynamicDisplayLevels="4"
        orientation="Horizontal" 
        IncludeStyleBlock="False" 
        datasourceid="MenuSource"    
        runat="server" Height="30px" onmenuitemdatabound="NavigationMenu_MenuItemDataBound">

        <staticmenuitemstyle ItemSpacing="40" CssClass="staticMenuItemStyle"/>
        <statichoverstyle CssClass="staticHoverStyle" />
        <StaticSelectedStyle CssClass="staticMenuItemSelectedStyle"/> 
        <DynamicMenuItemStyle CssClass="dynamicMenuItemStyle" />      
        <dynamichoverstyle CssClass="menuItemMouseOver" />
        <DynamicMenuStyle CssClass="menuItem" />
        <DynamicSelectedStyle CssClass="menuItemSelected" />

        <DataBindings>        
             <asp:MenuItemBinding DataMember="siteMapNode" 
                NavigateUrlField="url" TextField="title"  
                    ToolTipField="description" />
        </DataBindings>
      </asp:menu>
       <asp:TreeView ID="NavigationTreeView" runat="server" Visible="False" 
        DataSourceID="MenuSource" />
<div id="e">
        <asp:Label ID="lblMapPath" runat="server" Text="You are here:"></asp:Label>
        <asp:SiteMapPath ID="SiteMapPath2" runat="server" 
                RenderCurrentNodeAsLink="true" 
                CssClass="currentNodeStyle"
            PathSeparator=" >> ">
            <PathSeparatorStyle ForeColor="#5D7B9D" CssClass="currentNodeStyle" />
            <CurrentNodeStyle ForeColor="#333333" CssClass="currentNodeStyle" />
            <NodeStyle ForeColor="#7C6F57"  CssClass="currentNodeStyle"  />
            <RootNodeStyle  ForeColor="#5D7B9D" CssClass="currentNodeStyle"  />
    </asp:SiteMapPath> 
        <asp:SiteMapDataSource ID="MenuSource" runat="server" ShowStartingNode="true" 
            StartFromCurrentNode="false" />
</div>    

//使用样式表

div.hideSkiplink
{
    background-color: #C3D603;
    width: 100%;
}

div.menu
{
    padding: 4px 0px 4px 8px;
}

div.menu ul
{
    list-style: none;
    margin: 0px;
    padding: 0px;
    width: auto;
}

div.menu ul li a, div.menu ul li a:visited
{
    background-color: #C3D603;
    border: 1px solid #E4E4E4;
    color: #666666;
    display: block;
    line-height: 1.35em;
    padding: 4px 20px;
    text-decoration: none;
    white-space: nowrap;
    font-weight: normal;
}

div.menu ul li a:hover
{
    background-color: #bfcbd6;
    color: #465c71;
    text-decoration: none;
}

div.menu ul li a:active
{
    background-color: #465c71;
    color: #cfdbe6;
    text-decoration: none;
}

0 个答案:

没有答案