我正在使用 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
public string PageSection { get; set; }
将 MasterType 页面指令添加到内容页面的顶部
Add a MasterType page directive to the top of your content pages
<%@ MasterType VirtualPath="~/foo.master" %>
在你的内容页面代码后面,设置母版页的PageSection属性
In your content page code behind, set the PageSection property of the master page
Master.PageSection = "home";
在您的母版页中,将正文标记设为服务器标记
In your master page, make the body tag a server tag
<body ID="bodyTag" runat="server">
在后面的母版页代码中,使用该属性在body标签上设置一个类
In the master page code behind, use that property to set a class on the body tag
bodyTag.Attributes.Add("class", this.PageSection);
为每个导航项赋予唯一的 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
.home #homeNavItem,
.contact #contactNavItem
{
color: #f00;
}
这篇关于更改导航 ID 以突出显示当前页面 ASP.NET 的编程解决方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
MVC 中的 GoogleWebAuthorizationBroker 用于 Google Drive 访GoogleWebAuthorizationBroker in MVC For Google Drive Access(MVC 中的 GoogleWebAuthorizationBroker 用于 Google Drive 访问)
为什么我得到 System.UnauthorizedAccessException 对路径Why do I get System.UnauthorizedAccessException Access to the path #39;Google.Apis.Auth#39; is denied(为什么我得到 System.UnauthorizedAccessExcep
WinRT - 如何从导航历史记录中忽略或删除页面WinRT - How to ignore or delete page from navigation history(WinRT - 如何从导航历史记录中忽略或删除页面)
寻找适用于桌面应用程序的 Visual Studio 工具箱样Looking for a Visual Studio toolbox style navigation for desktop applications(寻找适用于桌面应用程序的 Visual Studio 工具箱样式导航)
WPF中类似访问的数据导航?access-like data navigation in WPF?(WPF中类似访问的数据导航?)
Windows Phone 8 页面之间的导航问题Windows Phone 8 navigation issue between pages(Windows Phone 8 页面之间的导航问题)