I am working on a web application that has a single master page and several content pages. Each page will have a small sidebar to the right of the main content with some brief content. However, that brief content is specific to the page you are on. I can't decide whether to put that on each individual page, or in the master page in a MultiView with some logic in code-behind to specify which view is shown based on which page you are on.
我正在开发一个具有单个母版页和几个内容页的Web应用程序。每个页面的主要内容右侧都有一个小侧边栏,并附有一些简短的内容。但是,该简短内容特定于您所在的页面。我无法决定是将它放在每个单独的页面上,还是放在MultiView的母版页中,在代码隐藏中使用某些逻辑来指定哪个视图根据您所在的页面显示。
Which seems more elegant? I'm still fairly new with ASP.NET and I'm trying to get a good feel for proper architecture, etc.
哪个看起来更优雅?我对ASP.NET仍然相当新,我正在尝试对正确的架构等感觉良好。
3 个解决方案
#1
You can create multiple content placeholders in a single masterpage. So in your case I would create two. One for the article's content and one for the sidebar like:
您可以在单个母版页中创建多个内容占位符。所以在你的情况下,我会创建两个。一篇用于文章的内容,另一篇用于侧边栏:
<!-- some html-->
<asp:contentplaceholder id="ArticleContents" runat="server">
</asp:contentplaceholder>
<!-- some more html-->
<asp:contentplaceholder id="ArticleSidebar" runat="server">
</asp:contentplaceholder>
<!-- even more html-->
then you could have the article contents and the sidebar contents both in the same page and place it in the correct spot using something like
然后你可以将文章内容和侧边栏内容放在同一页面中,并使用类似的东西将它放在正确的位置
<asp:Content ID="article" ContentPlaceHolderID="ArticleContents" Runat="Server">
Your article
</asp:Content>
<asp:Content ID="sidebar" ContentPlaceHolderID="ArticleSidebar" Runat="Server">
Your sidebar
</asp:Content>
#2
If you want some manageability in the case of your site getting larger and needing more of these custom sidebars then I would not put anything beyond standard layout in the master page.
如果您希望在站点变得更大并且需要更多这些自定义侧栏的情况下具有一定的可管理性,那么我不会在主页面中放置超出标准布局的任何内容。
What is wrong with having an additional ContentPlaceHolder in the side bar and just adding the content into Content controls on each content page?
在侧栏中添加额外的ContentPlaceHolder并将内容添加到每个内容页面的内容控件中有什么问题?
Your approach seems overly complex to me.
你的方法对我来说似乎过于复杂。
#3
You could also put that additional code into a user control (or two). The content page would then include the user control appropriate to that page for the right sidebar.
您还可以将其他代码放入用户控件(或两个)中。然后,内容页面将包含适合右侧边栏的该页面的用户控件。
#1
You can create multiple content placeholders in a single masterpage. So in your case I would create two. One for the article's content and one for the sidebar like:
您可以在单个母版页中创建多个内容占位符。所以在你的情况下,我会创建两个。一篇用于文章的内容,另一篇用于侧边栏:
<!-- some html-->
<asp:contentplaceholder id="ArticleContents" runat="server">
</asp:contentplaceholder>
<!-- some more html-->
<asp:contentplaceholder id="ArticleSidebar" runat="server">
</asp:contentplaceholder>
<!-- even more html-->
then you could have the article contents and the sidebar contents both in the same page and place it in the correct spot using something like
然后你可以将文章内容和侧边栏内容放在同一页面中,并使用类似的东西将它放在正确的位置
<asp:Content ID="article" ContentPlaceHolderID="ArticleContents" Runat="Server">
Your article
</asp:Content>
<asp:Content ID="sidebar" ContentPlaceHolderID="ArticleSidebar" Runat="Server">
Your sidebar
</asp:Content>
#2
If you want some manageability in the case of your site getting larger and needing more of these custom sidebars then I would not put anything beyond standard layout in the master page.
如果您希望在站点变得更大并且需要更多这些自定义侧栏的情况下具有一定的可管理性,那么我不会在主页面中放置超出标准布局的任何内容。
What is wrong with having an additional ContentPlaceHolder in the side bar and just adding the content into Content controls on each content page?
在侧栏中添加额外的ContentPlaceHolder并将内容添加到每个内容页面的内容控件中有什么问题?
Your approach seems overly complex to me.
你的方法对我来说似乎过于复杂。
#3
You could also put that additional code into a user control (or two). The content page would then include the user control appropriate to that page for the right sidebar.
您还可以将其他代码放入用户控件(或两个)中。然后,内容页面将包含适合右侧边栏的该页面的用户控件。