Do you prefer Master Page or User Controls?

C

Cirene

I know that sometimes referring to controls deep in a page using a Master
Page can be funky.

For a website using a standard header/footer/nav, do you prefer using User
Controls for the common items, or do you prefer Master Pages?

What is best from your experience? I've downloaded a few sample projects
(like for the Telerik Rad Controls) and have noticed that they like to use
User Controls.

What are the pros/cons of each?

Thanks.
 
J

jc

In addition to Eliyahu's response, MasterPages are actually UserControls
anyway... There is often a misconception (not aimed at you) that MasterPages
are somehow the ASP.NET implementation of framesets - nothing could be
further from the truth...

Eliyahu is also correct in that MasterPages do introduce a certain level of
complexity, but it's not exactly rocket science... :)

IMO, MasterPages were one of the major innovations in ASP.NET 2, and I
personally never use anything else for common layout.

IMHO

Master pages are not really user control. It's really hard to debug on
user control but master page.
 
D

David Wier

I hate to disagree with you, but Mark is right - according to Microsoft,
Masterpages become implementations of User controls on the pages

David Wier
http://aspnet101.com
http://iWritePro.com - One click PDF, convert .doc/.rtf/.txt to HTML with no
bloated markup


In addition to Eliyahu's response, MasterPages are actually UserControls
anyway...
IMO, MasterPages were one of the major innovations in ASP.NET 2, and I
personally never use anything else for common layout.

IMHO

Master pages are not really user control. It's really hard to debug on
user control but master page.
 
M

Madhur

I agree with David.

MasterPage class is derived from System.Web.UI.UserControl as opposed to
System.Web.UI.Page.
 
E

Eliyahu Goldin

Yes and no.

Technically, yes, master pages are user controls. But from development
pattern perspective they are very different. Typically, regular user
controls address one well-defined and limited task whereas master pages are
commonly used as a base for building the whole page with much richer markup
and code-behind. Perhaps that's why many developers don't perceive master
pages as user controls.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
 
J

Juan T. Llibre

re:
!> MasterPage class is derived from System.Web.UI.UserControl as opposed to System.Web.UI.Page.

The UserControl, Page and MasterPage classes all are subclasses of System.Web.UI.

See :
http://quickstarts.asp.net/QuickStartv20/util/classbrowser.aspx?namespace=System.Web.UI

When an HTTP request is made for a page at run time, the master page and content
pages are combined into a single class with the same name as the content pages.

The *resulting* compiled, merged class derives from the Page class.

The MasterPage class derives (inherits, actually) from Control,
and is last in a chain which includes Control, TemplateControl and UserControl:

Here's the inheritance hierarchy for the MasterPage class :

System..::.Object
System.Web.UI..::.Control
System.Web.UI..::.TemplateControl
System.Web.UI..::.UserControl
System.Web.UI..::.MasterPage

The master page is initialized as the top control in a page’s control hierarchy by
clearing the page’s Controls array and adding the master page to the Control collection.

The master page initialization happens after the PreInit event
fires for a Page object, but before the Init event fires.
 
P

Peter Bromberg [C# MVP]

I see a bunch of off-topic discussion about whether MasterPages are
userControls (they are). I use MasterPages quite frequently as they make it
very easy to "skin" a page with a consistent layout, theme and features.
They do introduce an additional level of complexity from a programmatic
perspective but as others have indicated, once you understand what a
MasterPage actually is, it's not rocket science.

Usercontrols fit in more as specific units of functionality to be dropped on
to the page proper. Hope that helps.
Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top