![]() |
|
|
|||||||
![]() |
ASP Net - Do you prefer Master Page or User Controls? |
|
|
Thread Tools | Search this Thread |
|
|
#1 |
|
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 |
|
|
|
|
#2 |
|
Posts: n/a
|
On 20 mayo, 06:22, "Mark Rae [MVP]" <m...@markNOSPAMrae.net> wrote:
> "Cirene" <cir...@nowhere.com> 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. |
|
|
|
#3 |
|
Posts: n/a
|
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:b09e0e82-d264-47ba-b08d-... On 20 mayo, 06:22, "Mark Rae [MVP]" <m...@markNOSPAMrae.net> wrote: > "Cirene" <cir...@nowhere.com> 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. |
|
|
|
#4 |
|
Posts: n/a
|
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:b09e0e82-d264-47ba-b08d-... > On 20 mayo, 06:22, "Mark Rae [MVP]" <m...@markNOSPAMrae.net> wrote: >> "Cirene" <cir...@nowhere.com> 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. > > |
|
|
|
#5 |
|
Posts: n/a
|
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:b09e0e82-d264-47ba-b08d-... > >> 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/libr...asterpage.aspx > > > -- > Mark Rae > ASP.NET MVP > http://www.markrae.net |
|
|
|
#6 |
|
Posts: n/a
|
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/QuickStar...=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:9570A98B-688A-42A9-AFDF-... >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:b09e0e82-d264-47ba-b08d-... >> On 20 mayo, 06:22, "Mark Rae [MVP]" <m...@markNOSPAMrae.net> wrote: >>> "Cirene" <cir...@nowhere.com> 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. >> >> > |
|
|
|
#7 |
|
Posts: n/a
|
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. > |
|