ASP.NET:当前页面的高亮显示菜单项 [英] ASP.NET: Highlight menu item of current page

查看:85
本文介绍了ASP.NET:当前页面的高亮显示菜单项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在试图找出突出一个asp.net菜单的当前选择的菜单项的一种简单的方法(这样用户就知道他们是哪个网页上),但无论怎样我都试过,我不能得到它的工作。在我的标记,我有:

I've been trying to find an easy way of highlighting the current selected menu item of an asp.net menu (so the user knows which page they are on), but no matter what I have tried I can't get it to work. In my markup I have:

<asp:Menu ID="NavigationMenu" runat="server" CssClass="menu" EnableViewState="false" IncludeStyleBlock="false" Orientation="Horizontal" StaticSelectedStyle-ForeColor="#99CCFF" DynamicSelectedStyle-ForeColor="#99CCFF">
    <Items>
        <asp:MenuItem NavigateUrl="~/Default.aspx" Text="Operations"/>
        <asp:MenuItem NavigateUrl="~/Analysis.aspx" Text="Analysis"/>
        <asp:MenuItem NavigateUrl="~/Dashboard.aspx" Text="Dashboard"/>
        <asp:MenuItem NavigateUrl="~/Flashboard.aspx" Text="Flashboard"/>
        <asp:MenuItem NavigateUrl="~/Spacequest.aspx" Text="SQ OBP"/>
    </Items>
</asp:Menu>

和在服务器侧的Page_Load功能:

And in the server side Page_Load function:

((Menu)Master.FindControl("NavigationMenu")).Items[0].Selected = true;

但是,这并不正常工作。我试着使用Sitemap(即使一个网站地图是不是我想用什么),并已也不奏效。任何想法?

But this does not work. I tried using a sitemap (even though a sitemap is not what I want to use) and that hasn't worked either. Any ideas?

推荐答案

还有,你可以在菜单之内时使用 StaticSelectedStyle 属性。

There's a StaticSelectedStyle property that you can use inside your menu.

<asp:menu [...]>
        <staticselectedstyle backcolor="LightBlue"
          borderstyle="Solid"
          bordercolor="Black"
          borderwidth="1"/>

        [...]
</asp:menu>

请参阅here更多信息

另外,如果有应用到所选择的项目(这我不知道,如果有,但它会很方便)一类你可以简单地挂接到与你的CSS。这将是比使用 StaticSelectedStyle 属性更加美好的方式。

Also, if there's a class applied to the selected item (which i'm not sure if there is but it would be handy) you can simply hook into that with your CSS. This would be a much nicer way than using the StaticSelectedStyle property.

更新

值得也注意到,您的使用 IncludeStyleBlock =的假将产生控制所选项目所必需的CSS停止你的菜单。

It's worth noting also that your use of IncludeStyleBlock="false" will stop your menu from generating the CSS necessary to control the selected item.

随着样式块关闭,你必须提供你自己的风格和自动生成的样式的菜单将不会被使用。

With the style block turned off, you have to provide your own styles and the auto-generated styles of the menu will not be used.

从MSDN:

如果您将此属性设置为false,则不能设置样式属性。
  例如,您不能添加DynamicHoverStyle,前景色属性,
  标记或设置code中的DynamicHoverStyle.ForeColor属性。

If you set this property to false, you cannot set style properties. For example, you cannot add a DynamicHoverStyle-ForeColor attribute in markup or set the DynamicHoverStyle.ForeColor property in code.

来源:<一个href=\"http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.menu.includestyleblock.aspx\">http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.menu.includestyleblock.aspx

这篇关于ASP.NET:当前页面的高亮显示菜单项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆