Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / May 2008

Tip: Looking for answers? Try searching our database.

Do you prefer Master Page or User Controls?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Cirene - 20 May 2008 10:08 GMT
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.
Eliyahu Goldin - 20 May 2008 10:43 GMT
I am using user controls for the header and the footer. Master pages, with
all their convenience, certainly do introduce an extra level of complexity.
There are many issues and considerations related to them. I use them for
specific purposes when I anticipate that they can cover significant
functionality. Header and footer are often general for all pages and don't
usually include any reach functionality.

Signature

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

>I know that sometimes referring to controls deep in a page using a Master
>Page can be funky.
[quoted text clipped - 9 lines]
>
> Thanks.
Mark Rae [MVP] - 20 May 2008 11:22 GMT
>I know that sometimes referring to controls deep in a page using a Master
>Page can be funky.
[quoted text clipped - 7 lines]
>
> What are the pros/cons of each?

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.

Signature

Mark Rae
ASP.NET MVP
http://www.markrae.net

jc - 20 May 2008 14:38 GMT
> >I know that sometimes referring to controls deep in a page using a Master
> >Page can be funky.
[quoted text clipped - 18 lines]
> 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.
David Wier - 20 May 2008 15:03 GMT
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

> "Cirene" <cir...@nowhere.com> wrote in message
>
> news:ewc8XkluIHA.3780@TK2MSFTNGP03.phx.gbl...
<snip>
> In addition to Eliyahu's response, MasterPages are actually UserControls
> anyway...
<snip>
> 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.
Madhur - 20 May 2008 15:09 GMT
I agree with David.

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

--
Madhur
http://blogs.msdn.com/mahuja

>I hate to disagree with you, but Mark is right - according to Microsoft,
>Masterpages become implementations of User controls on the pages
[quoted text clipped - 18 lines]
> Master pages are not really user control. It's really hard to debug on
> user control but master page.
Juan T. Llibre - 20 May 2008 17:25 GMT
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.

Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
>I agree with David.
>
[quoted text clipped - 25 lines]
>> Master pages are not really user control. It's really hard to debug on
>> user control but master page.
Mark Rae [MVP] - 20 May 2008 15:11 GMT
> IMHO
>
> MasterPages are not really UserControl.

That's incorrect. A MasterPage most certainly is a UserControl. In fact, all
MasterPages by default inherit from the UserControl class:

http://msdn.microsoft.com/en-us/library/system.web.ui.masterpage.aspx

Signature

Mark Rae
ASP.NET MVP
http://www.markrae.net

Eliyahu Goldin - 20 May 2008 15:54 GMT
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.

Signature

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

>> IMHO
>>
[quoted text clipped - 4 lines]
>
> http://msdn.microsoft.com/en-us/library/system.web.ui.masterpage.aspx
Mark Rae [MVP] - 20 May 2008 16:21 GMT
>>> IMHO
>>>
[quoted text clipped - 6 lines]
>
> Technically, yes, master pages are user controls.

There's no need to go any further... :-)

> Perhaps that's why many developers don't perceive master pages as user
> controls.

Nevertheless that's what they are, regardless of how many developers
perceive them....

Lots of developers, especially beginners, perceive MasterPages as
framesets - that doesn't mean they're framesets.

In fact, it's been my experience that once developers realise that
MasterPages are precisely UserControls, then their understanding of what
they are and how to use them increases dramatically...

Signature

Mark Rae
ASP.NET MVP
http://www.markrae.net

Aidy - 20 May 2008 11:24 GMT
For the basic nav elements use Master pages.  For individual items on a page
I use user controls if I want to use the element on more than one page.

>I know that sometimes referring to controls deep in a page using a Master
>Page can be funky.
[quoted text clipped - 9 lines]
>
> Thanks.
Peter Bromberg [C# MVP] - 22 May 2008 16:30 GMT
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
>I know that sometimes referring to controls deep in a page using a Master
>Page can be funky.
[quoted text clipped - 9 lines]
>
> Thanks.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.