Programmatic solution to change navigation id to highlight current page ASP.NET(更改导航 ID 以突出显示当前页面 ASP.NET 的编程解决方案)
问题描述
我正在使用 Visual Studio 2008 和 ASP.NET 3.5 编写网站.我设置了一个母版页来简化布局并保留内容页面而不是内容和布局.
I am writing a website with Visual Studio 2008 and ASP.NET 3.5. I have a masterpage set up to simplify the layout and to keep the content pages for content rather than content and layout.
导航是列表,css'd,所以它看起来像一个栏.为了在栏上突出显示页面,列表项需要看起来像这样 <li id="current">
.如果可以避免,我不想使用 <asp:ContentPlaceHolder>
.是否有一些代码可以添加到我的每个页面(或仅添加到母版页?)来完成此操作,或者我是否使用 <asp:ContentPlaceHolder>
's?
The navigation is list, css'd so it looks like a bar. In order to highlight the page on the bar, the list item needs to look like this <li id="current">
. I do not want to use <asp:ContentPlaceHolder>
if I can avoid it. Is there some code I can add to each of my pages (or just to the masterpage?) to accomplish this or am I stuck using <asp:ContentPlaceHolder>
's?
推荐答案
向母版页添加一个名为 Page Section 的属性
Add a property to your master page called Page Section
将 MasterType 页面指令添加到内容页面的顶部
Add a MasterType page directive to the top of your content pages
在你的内容页面代码后面,设置母版页的PageSection属性
In your content page code behind, set the PageSection property of the master page
在您的母版页中,将正文标记设为服务器标记
In your master page, make the body tag a server tag
在后面的母版页代码中,使用该属性在body标签上设置一个类
In the master page code behind, use that property to set a class on the body tag
为每个导航项赋予唯一的 ID 属性.
Give each of your nav items a unique ID attribute.
在你的 css 中,根据当前页面类更改导航项的显示
In your css, change the display of the nav items based on the current page class
这篇关于更改导航 ID 以突出显示当前页面 ASP.NET 的编程解决方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!