tags:

views:

71

answers:

4

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.

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.

A: 

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.

Jeff Siver
+2  A: 

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?

Your approach seems overly complex to me.

Charlie
>What is wrong with having an additional ContentPlaceHolder in the side bar and just adding the content into Content controls on each content page? ... Can you elaborate on that a bit? Like I said, I'm still fairly new to ASP.NET.
Mike C.
Essentially you can have multiple ContentPlaceHolders on a master page. The reason for having multiples is to preserve layout within your master page. It's about the seperation of layout and content. The master page is layout and the content pages are, well, content.
Charlie
+4  A: 

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>
olle
May I ask what having another ContentPlaceHolder gains me over adding the content directly in the main ContentPlaceHolder?
Mike C.
I assumed you needed to render it at a completely different location in the html then the article. If that's not the case then you gain nothing and you would use only 1 placeholder. Then the question makes little sense to me though. Why the multiview solution if you already have a page per article and the sidebar has 1:1 relation to the article?
olle
Mike - see the comment on my post.
Charlie
Charles, your comment makes sense. Thank you. Let me play around with it for a bit.
Mike C.
A: 

I would be inclined to solve this one using the master page + multiview control, or do what Jeff S recommended and use a separate user control.

Matt Ball