大型网站的母版页

时间:2022-12-30 20:07:08

I've just been learning about master pages in ASP.NET 2.0.

我刚刚学习了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?

有没有人有在大型网站上使用它们的经验?

6 个解决方案

#1


5  

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.

我很确定我在ASP.NET MVC的上下文中只使用了母版页,因此我不确定它是否与Web表单不同,但根据我的经验,它们不仅非常出色,而且我无法想象不使用它们。母版页是对网页的代码继承。

#2


5  

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.

然后在创建aspx页面时,您需要提及要使用哪个母版页以及在哪个占位符中放置哪些内容。

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

在我工作的地方,我们广泛地为一些大公司使用母版页和网页控件,与其他公司提供的服务相比,它给我们带来了优势。

#3


1  

They are extremely useful, especially in a CMS environment and for large sites, and as MattMitchell says it's inconceivable that you would build a large site without them.

它们非常有用,特别是在CMS环境和大型站点中,正如MattMitchell所说,没有它们构建一个大型站点是不可思议的。

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.

选择模板,每个模板都有不同的可编辑区域,完成工作。母版页也可以继承,因此您可以拥有一个Style.Master,派生一个Header.Master,然后从中派生所有基于布局的模板。

#4


0  

Master Pages have made building template-able websites easy.

Master Pages使构建模板的网站变得容易。

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.

我认为使用母版页构建网站最棘手的部分是知道何时将内容放入母版页以及何时将内容放入子页面上的ContentPlaceHolder中。通常,动态内容会进入占位符,而静态项目会进入母版页,但有时会出现灰色区域。这主要是一个设计/架构问题。

#5


0  

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.

在实践中,我经常发现不使用MasterPages开发的网站。它们可以简单轻松地操作网站外观,还可以轻松实现导航元素和共享内容。

ASP.Net 3.5 even allows multiple contentpages and manipulation of header sections across a single master pages.

ASP.Net 3.5甚至允许跨单个母版页的多个内容页面和标题部分的操作。

I rate it as being in the Top 10 tools for Web Developers using ASP.Net.

我认为它是使用ASP.Net的Web开发人员的十大工具之一。

Even ASP.Net MVC uses MasterPages and all the samples Paul Haack and his crowd put's together makes use of them.

即使是ASP.Net MVC也使用了MasterPages,Paul Haack和他的观众一起使用的所有样本都使用了它们。

#6


0  

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.

我在这里回应其他声音。我在2.0中使用了Master Pages,这个功能对我来说很棒。我一直在嵌入横幅,标准化背景,Active Dir捕获和其他JavaScript功能,以便在整个应用程序中使用,保持外观和感觉的一致性,而无需在多个页面上复制工作。很棒的功能。

#1


5  

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.

我很确定我在ASP.NET MVC的上下文中只使用了母版页,因此我不确定它是否与Web表单不同,但根据我的经验,它们不仅非常出色,而且我无法想象不使用它们。母版页是对网页的代码继承。

#2


5  

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.

然后在创建aspx页面时,您需要提及要使用哪个母版页以及在哪个占位符中放置哪些内容。

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

在我工作的地方,我们广泛地为一些大公司使用母版页和网页控件,与其他公司提供的服务相比,它给我们带来了优势。

#3


1  

They are extremely useful, especially in a CMS environment and for large sites, and as MattMitchell says it's inconceivable that you would build a large site without them.

它们非常有用,特别是在CMS环境和大型站点中,正如MattMitchell所说,没有它们构建一个大型站点是不可思议的。

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.

选择模板,每个模板都有不同的可编辑区域,完成工作。母版页也可以继承,因此您可以拥有一个Style.Master,派生一个Header.Master,然后从中派生所有基于布局的模板。

#4


0  

Master Pages have made building template-able websites easy.

Master Pages使构建模板的网站变得容易。

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.

我认为使用母版页构建网站最棘手的部分是知道何时将内容放入母版页以及何时将内容放入子页面上的ContentPlaceHolder中。通常,动态内容会进入占位符,而静态项目会进入母版页,但有时会出现灰色区域。这主要是一个设计/架构问题。

#5


0  

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.

在实践中,我经常发现不使用MasterPages开发的网站。它们可以简单轻松地操作网站外观,还可以轻松实现导航元素和共享内容。

ASP.Net 3.5 even allows multiple contentpages and manipulation of header sections across a single master pages.

ASP.Net 3.5甚至允许跨单个母版页的多个内容页面和标题部分的操作。

I rate it as being in the Top 10 tools for Web Developers using ASP.Net.

我认为它是使用ASP.Net的Web开发人员的十大工具之一。

Even ASP.Net MVC uses MasterPages and all the samples Paul Haack and his crowd put's together makes use of them.

即使是ASP.Net MVC也使用了MasterPages,Paul Haack和他的观众一起使用的所有样本都使用了它们。

#6


0  

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.

我在这里回应其他声音。我在2.0中使用了Master Pages,这个功能对我来说很棒。我一直在嵌入横幅,标准化背景,Active Dir捕获和其他JavaScript功能,以便在整个应用程序中使用,保持外观和感觉的一致性,而无需在多个页面上复制工作。很棒的功能。