难道一个母版知道正在显示的内容页面? [英] Does a MasterPage know what page is being displayed?

查看:87
本文介绍了难道一个母版知道正在显示的内容页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我浏览使用MasterPages在网站上,应用程序是否会知道我是什么网页上?如果是这样,它存储在一个对象,我可以访问?

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?

我问的原因是这样我就可以取代这个:

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>

随着导航,它通过具有列表项的ID设置为当前突出了链接的网页更优雅的解决方案。目前,每个页面重新创建其各自的链路的ID设置为当前导航。

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.

推荐答案

我与克里斯同意:使用控制来处理这个菜单的显示,并使其认识到应该强调什么联系。下面是我经常使用的方法。如果你有这将需要不同的风格相同的链接多个页面可能变得更为复杂,但你的想法。

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

这篇关于难道一个母版知道正在显示的内容页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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