問題描述
我正在使用 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模板網!