Master Pages for large web sites
Asked Answered
C

6

5

I've just been learning about master pages in ASP.NET 2.0.

They sound great, but how well do they work in practice?

Does anybody have experience of using them for a large web site?

Clavichord answered 9/8, 2008 at 9:51 Comment(0)
D
6

I'm pretty sure I've only used master pages in the context of ASP.NET MVC so I'm not sure if it differs from web forms but in my experience they are not only excellent but I couldn't imagine not using them. Master pages are code inheritance to web pages.

Diva answered 9/8, 2008 at 9:55 Comment(0)
C
5

They are a must if you want to maintain the look of your application throughout all the pages in the application.

They are fairly easy to use:

First of all, design your master page and define where you want the content to be placed:

<%@ Master ... %>

<%-- HTML code --%>
<asp:ContentPlaceHolder id="plhMainContent" runat="server" />
<%-- HTML code --%>

You can have any number of place holders, just give them proper identifiers because you'll need them later.

Then when creating an aspx page, you will need to mention which master page to use and in which place holder to put what content.

<%@ Page ... master="~/MasterPage.master" ... %>

<asp:Content ID="ContentIdentifier" ContentPlaceholderid="plhMainContent" runat="server">
    <%-- More HTML here --%>
    <%-- Insert web controls here --%>
</asp:content>

Just make sure you link to the correct master page and that your content refers to the correct place holder.

Master pages save a lot of time and are very powerful. There are tutorials out there, learn the power of place holders and web controls.

Where I work we use master pages and web controls extensively for some major corporations, it gives us an edge when comparing with what other companies can offer.

Cocoa answered 9/8, 2008 at 12:25 Comment(0)
D
1

They are extremely useful, especially in a CMS environment and for large sites, and as MattMitchell says it's inconceivable that you would build a large site without them.

Select template, each template has different editable areas, job done. Master pages can also be inherited, so you can have a Style.Master, derive a Header.Master, then derive all of your layout-based templates from that.

Defrayal answered 9/8, 2008 at 11:41 Comment(0)
S
0

Master Pages have made building template-able websites easy.

I think the trickiest part in building a website using master pages is knowing when to put things into the master page and when to put things into the ContentPlaceHolder on the child page. Generally, dynamic stuff goes into the placeholder while static items go into the master page, but there is sometimes a gray area. It's mostly a design/architecture question.

Seasonal answered 9/8, 2008 at 12:13 Comment(0)
S
0

In practise I don't often find sites developed not using MasterPages. They allow simple and easy manipulation of site look and feel and also makes navigation elements and shared content pieces a breeze.

ASP.Net 3.5 even allows multiple contentpages and manipulation of header sections across a single master pages.

I rate it as being in the Top 10 tools for Web Developers using ASP.Net.

Even ASP.Net MVC uses MasterPages and all the samples Paul Haack and his crowd put's together makes use of them.

Siana answered 9/8, 2008 at 12:50 Comment(0)
C
0

I echo other voices in here. I have used Master Pages in 2.0 and the feature have been great to me. I have been embedding banners, standardized background, captures from Active Dir and other JavaScript features on it for use throughout the app, maintaining the look and feel consistency and without the need to duplicate the effort on multiple pages. Great feature.

Cobaltous answered 9/8, 2008 at 15:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.