tags:

views:

480

answers:

6

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?

+5  A: 

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.

Graphain
+1  A: 

They are extremely useful, especially in a CMS environment and for large sites, and as Graphain 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.

tags2k
A: 

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.

y0mbo
+5  A: 

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.

GoodEnough
A: 

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.

Diago
A: 

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.

ciroric