問(wèn)題描述
當(dāng)我使用 MasterPages 在網(wǎng)站上導(dǎo)航時(shí),應(yīng)用程序是否知道我在哪個(gè)頁(yè)面上?如果是這樣,它是否將其存儲(chǔ)在我可以訪問(wèn)的對(duì)象中?
When I navigate on a website utilizing MasterPages, does the application know what page I am on? If so, does it store it in an object I can access?
我問(wèn)的原因是我可以替換這個(gè):
The reason I am asking is so I can replace this:
//masterpage
<div id="nav_main">
<ul><asp:ContentPlaceHolder ID="navigation" runat="server">
</asp:ContentPlaceHolder></ul>
</div>
//content page(s)
<asp:Content ContentPlaceHolderID="navigation" ID="theNav" runat="server">
<li><a href="default.aspx">Home</a></li>
<li id="current"><a href="faq.aspx">FAQ</a></li>
<li><a href="videos.aspx">Videos</a></li>
<li><a href="#">Button 4</a></li>
<li><a href="#">Button 5</a></li>
</asp:Content>
使用更優(yōu)雅的導(dǎo)航解決方案,通過(guò)將列表項(xiàng)的 ID 設(shè)置為當(dāng)前"來(lái)突出顯示指向頁(yè)面的鏈接.目前,每個(gè)頁(yè)面都會(huì)重新創(chuàng)建導(dǎo)航,并將其各自鏈接的 ID 設(shè)置為 current.
With a more elegant solution for the navigation, which highlights the link to the page by having the list item's ID set to "current". Currently each page recreates the navigation with its respective link's ID set to current.
推薦答案
我同意 Chris:使用控件來(lái)處理此菜單的顯示,并使其知道應(yīng)該突出顯示哪個(gè)鏈接.這是我經(jīng)常使用的一種方法.如果您有多個(gè)頁(yè)面需要不同樣式的相同鏈接,這可能會(huì)變得更加復(fù)雜,但您明白了.
I'd concur with Chris: use a control to handle display of this menu and make it aware of what link should be highlighted. Here's a method I use regularly. It may become more complex if you've got multiple pages that would need the same link styled differently, but you get the idea.
Dim thisURL As String = Request.Url.Segments(Request.Url.Segments.Count - 1)
Select Cast thisUrl
Case "MenuItem1.aspx"
lnkMenu1.CssClass = "Current"
Case "MenuItem2.aspx"
lnkMenu2.CssClass = "Current"
End Select
這篇關(guān)于MasterPage 是否知道正在顯示的頁(yè)面?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!