Do you prefer Master Page or User Controls?

Discussion in 'ASP .Net' started by Cirene, May 20, 2008.

  1. Cirene

    Cirene Guest

    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.
     
    Cirene, May 20, 2008
    #1
    1. Advertising

  2. Cirene

    jc Guest

    On 20 mayo, 06:22, "Mark Rae [MVP]" <> wrote:
    > "Cirene" <> wrote in message
    >
    > news:...
    >
    > >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?

    >
    > 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.
     
    jc, May 20, 2008
    #2
    1. Advertising

  3. Cirene

    David Wier Guest

    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


    "jc" <> wrote in message
    news:...
    On 20 mayo, 06:22, "Mark Rae [MVP]" <> wrote:
    > "Cirene" <> wrote in message
    >
    > news:...

    <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.
     
    David Wier, May 20, 2008
    #3
  4. Cirene

    Madhur Guest

    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

    "David Wier" <> wrote in message
    news:...
    >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
    >
    >
    > "jc" <> wrote in message
    > news:...
    > On 20 mayo, 06:22, "Mark Rae [MVP]" <> wrote:
    >> "Cirene" <> wrote in message
    >>
    >> news:...

    > <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, May 20, 2008
    #4
  5. 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


    "Mark Rae [MVP]" <> wrote in message
    news:...
    > "jc" <> wrote in message
    > news:...
    >
    >> 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
    >
    >
    > --
    > Mark Rae
    > ASP.NET MVP
    > http://www.markrae.net
     
    Eliyahu Goldin, May 20, 2008
    #5
  6. 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/
    ======================================
    "Madhur" <> wrote in message news:...
    >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
    >
    > "David Wier" <> wrote in message news:...
    >>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
    >>
    >>
    >> "jc" <> wrote in message
    >> news:...
    >> On 20 mayo, 06:22, "Mark Rae [MVP]" <> wrote:
    >>> "Cirene" <> wrote in message
    >>>
    >>> news:...

    >> <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.
    >>
    >>

    >
     
    Juan T. Llibre, May 20, 2008
    #6
  7. 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
    "Cirene" <> wrote in message
    news:...
    >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.
    >
     
    Peter Bromberg [C# MVP], May 22, 2008
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. clintonG
    Replies:
    17
    Views:
    914
    clintonG
    Oct 13, 2005
  2. Electrified Research
    Replies:
    5
    Views:
    2,490
    =?Utf-8?B?Q293Ym95IChHcmVnb3J5IEEuIEJlYW1lcikgLSBN
    Oct 11, 2005
  3. Doug McCann
    Replies:
    1
    Views:
    1,100
    William Brogden
    Aug 5, 2004
  4. Replies:
    6
    Views:
    351
  5. SerpentKiss2010
    Replies:
    0
    Views:
    2,528
    SerpentKiss2010
    Apr 6, 2011
Loading...

Share This Page