ASP.Net Menu Control renders incorrectly when used on a Master Page

梦想的初衷 提交于 2019-12-05 23:19:51

I remember seeing that at one point in a site of mine. Since then I ripped the menu out, but putting it back into my master page I don't see the flicker any more. Here's the code for a simple menu that works without flicker in a master page;

<asp:Menu ID="menu" 
    DataSourceID="sitemap" 
    runat="server" />
<asp:SiteMapDataSource 
    ID="sitemap" 
    ShowStartingNode="false" 
    runat="server" />

Not tried it myself, but how about setting the default class for the menu children to invisible (say, a class of invisibleMenu), which means it initially loads invisibly, and then using a bit of javascript to remove the invisibility? In jQuery, something like

$('.invisibleMenu').removeClass('invisibleMenu');

If I remember, I had the same problem and solve it in putting the menu in content place holder in the amster page:

<asp:ContentPlaceHolder ID="MenuZone" Runat="server">
   <asp:TreeView ID="TreeView1" Runat="server" DataSourceID="dsSiteMap" ImageSet="Simple"
                    NodeIndent="10" MaxDataBindDepth="3" ExpandDepth="0" OnTreeNodePopulate="TreeView1_TreeNodePopulate">
       <SelectedNodeStyle Font-Underline="True" ForeColor="#DD5555" HorizontalPadding="0px" VerticalPadding="0px"></SelectedNodeStyle>
       <NodeStyle Font-Names="Verdana" Font-Size="8pt" HorizontalPadding="0px" ForeColor="Black" NodeSpacing="0px" VerticalPadding="0px"></NodeStyle>
       <HoverNodeStyle Font-Underline="True" ForeColor="#DD5555"></HoverNodeStyle>
       <ParentNodeStyle Font-Bold="False" />
   </asp:TreeView>
   <asp:SiteMapDataSource ID="dsSiteMap" Runat="server" ShowStartingNode="False" />

And in not overwritting this placeholder in nested page.

Add the menu to an ASCX page or its own masterpage and include it into the main masterpage. I myself have never run into this issue but something similar has happened.

if know your problem that ASP.Net Menu Control renders incorrectly when used on a Master Page if the asp.net menu is not worked then use usercontrol not master page because we can use user control by easy wasy.

ClearCloud8

In case anyone else runs into this problem again, I had my issue resolved over here on another Stack Overflow thread:

How to get rid of ugly asp:Menu flickering?

Same issue was with me too. But solved by removing jquery calls. :) or you can download and keep the .js script file inside the script folder instead of referencing it from online.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!