ASP.net突出显示母版页中导航栏中的当前选项卡。 [英] ASP.net Highlighting current tab in Navigation Bar in a Master Page.

查看:151
本文介绍了ASP.net突出显示母版页中导航栏中的当前选项卡。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试让当前标签在导航栏上突出显示,以使我的寻呼机看起来更加用户友好。



我一直无法使用css因为伪类仅在单击页面时才起作用并且恢复到被访问的页面而不是活动。



我理解JQuery可以在这种情况下使用。

我的母版页底部有一个空的jquery脚本。



我的母版页中的html如下:



I am trying to get the current tab to be highlighted on a navigation bar to make my pager look more user friendly.

I have been unable to use css as the the pseudo classes only work when the page is clicked and reverts to page visited rather than active.

I understand JQuery can be used in this case.
I have an empty jquery script at the bottom of my master page.

my html in my masterpage is as follows:

<div class="clear hideSkiplink">
       <asp:Menu ID="NavigationMenu" runat="server" CssClass="menu"
           EnableViewState="false" IncludeStyleBlock="false" Orientation="Horizontal"
           onmenuitemclick="NavigationMenu_MenuItemClick">
           <Items>
               <asp:MenuItem NavigateUrl="~/Index.aspx" Text="Home" />
               <asp:MenuItem NavigateUrl="~/About.aspx" Text="About"/>
               <asp:MenuItem NavigateUrl="~/Contact.aspx" Text="Contact"/>
               <asp:MenuItem NavigateUrl="~/Admin/EditPageContent.aspx" Text="Edit Conetent"/>
               <asp:MenuItem NavigateUrl="~/Portfolio.aspx" Text="Portfolio"/>
               <asp:MenuItem NavigateUrl="~/Admin/AddToPortfolio.aspx" Text="Manage Portfolio"/>
           </Items>
       </asp:Menu>
   </div>





i我不确定使用什么jquery来使背景更改保持不变直到点击其他rmenu项目。



i am not sure what jquery to use to make the background change stay until anothe rmenu item is clicked.

推荐答案

最快的一个解决方案我建议将下面的代码加载到每个页面加载并用每个页面名称替换Home。



注意:还有很多其他方法可以做这......其中之一最快的方式是服务器端编码,因为你只有6页。



One of the quickest solution I would suggest is that put the below code on every page load and replace "Home" with every page name.

Note: There could be many other ways of doing this... One of the quickest way is server side coding as you have only 6 pages.

if (!IsPostBack)
            {
                Menu M = (Menu)this.Master.FindControl("NavigationMenu");
                foreach (MenuItem item in M.Items)
                {
                    if (item.Text == "Home")//Replace Home with the page name
                    {
                        item.Selected = true;
                    }
                }
            }


这篇关于ASP.net突出显示母版页中导航栏中的当前选项卡。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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