ASP.net 2.0 Migrating系列 - Master Pages
范维肖

在Visual Web Developer 2005里的新建里多了一个Master Pages,在微软的VWD2005的Guided Tour里有专门对它使用的介绍,可见它是ASP.NET2.0里的一大特色.
最早我们在做HTML页面的时候,有时会有遇到这样的情况:一个网站要有一个统一的风格,所以页面的样式是大体一致的,因此我们都喜欢做一个包括导航栏在内的Model页面,然后每次都打开它,然后另存为像aboutus.html这样的页面,然后再编辑,再保存。后来东西多了,我们就开始用Frameset把页面分开,像导航菜单,版权声名部分都用专门的frame。到了ASP时代,通常也是把版面设计和asp代码分开。设计完版面再填写代码,对于有相似样式的页面,我们也是通过copy样式的html代码来实现的,后来为了适应skin技术,有人开始做一个model页面,里面需要插入ASP的部分用类似$BlogContent$的标记来表示,然后用程序再去分析。到了ASP.NET的时代,有时我们也尝试着用userControl来实现frameset那样的思想。这些我们的“土方法”最终在VWD2005结束了,这个新的feature相比是VWD2005的设计者也是饱受了痛苦之后才设计出来帮助大家的吧。
这里是微软Migrating系列里对master pages的介绍:
Master pages are a new feature introduced in ASP.NET 2.0 to help you reduce development time for Web applications by creating a single place to maintain a consistent look and feel in a site. Master pages allow you to create a template that can be used to generate a common layout for many pages in the application. The primary goal of master pages is to avoid creating each page from scratch and having to repeat the layout code. Another benefit of using master pages is that if you want to change the layout of the pages in the application, you only have to update the master page, rather than each individual page.
Master Pages是ASP.NET 2.0里介绍的一个新特色,通过建立一个来控制一致的样式的页面,可以帮助你缩短开发web应用程序的时间。Master Pages允许你建立一个模板,这个模板用来生成一个使程序中的页面(如果需要样式一致的)具有相同的布局。Master pages的主要目的是为了避免我们从一个已经建好的页面里挖出那些控制页面样式的代码,然后在重复它们的建立页面的方法。使用Master pages的另一个好处是如果你想改变程序中页面的样式的时候,你只需要来改变这个master page就可以了,不用再一个一个的单独修改了。
A master page looks like any ordinary ASP.NET Web page except for the extension (.master instead of .aspx) and some special controls and header fields. Master pages must contain one or more <asp:ContentPlaceHolder> controls. These controls represent areas of replaceable content. Basically, anything that is not in a ContentPlaceHolder will appear on any page that uses the master page.
一个master page页面看起来像其他的普通的ASP.NET页面,除了扩展名由.master 来替代了.aspx和一些特殊的控件和标题字段。Master pages必须包含一个和更多的<asp:ContentPlaceHolder>控件。这些控件表示了那些需要替代的内容。基本上那些不在ContentPlaceHolder的内容都将出现在使用master page的页面里了。
Other than these key changes, a master page can contain any HTML or control that can be found on a normal ASP.NET page
除了这些关键地方的改变外,master page页面能包含一个普通的ASP.NET页面上能够存在的任意的HTML代码或者是控件。
看到这里,master pages可能和frame很像了吧,其实他们是不一样的,MS这样说他们的区别:
Although master pages and frames serve a similar purpose, master pages offer much more functionality. Unlike frames, using master pages allow you to:
·  Bookmark a page and recall all the information on the specific page, not just the default frame page. A master page isn't really a frame. It's a single page that contains collated content from the master page and the content page that builds on the master. Therefore it looks and acts like a single Web page rather than a frame.
·   Work in controls and tags rather than HTML. Thanks to Visual Studio, you don't have to worry about opening and closing the frame tags or modifying countless html attributes to ensure that each frame displays in the fashion you want. You can simply create the place holder and modify its properties through Visual Studio.
·  Leverage Visual Studio's code creation to visually design the layout, manage the frames, and provide all of the plumbing to link the content pages into the master page. You can add new content without having to worry that the overall HTML layout of the page will be affected. <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

ASP.net 2.0 Migrating系列 - Master Pages 感触相关推荐

  1. ASP.NET MVC Tip #31: 给 Master Pages 和 User Controls 传递数据

    原文地址:ASP.NET MVC Tip #31 – Passing Data to Master Pages and User Controls 原文作者:swalther 本文译者:QLeelul ...

  2. ASP.NET 2.0 中配合 Master Page 使用的优化 CSS 模型

    ASP.NET 2.0 中增加了内建的 MasterPage 的支持,这对我们来说是一个很大的便利.然而经过一段时间的使用,我发现 MasterPage 并不是那么完美:嵌套的 MasterPage ...

  3. ASP.NET 2.0 XML 系列(2): XML技术

    1. DTD XML最强大之处是允许自定义标签,但是对任何既有的应用程序来说,任何类型的标签以任意顺序出现并没有实际意义,所以必须对次序和标签的嵌套加以约束. DTD就是干这件事的,但是DTD缺少强类 ...

  4. ASP.NET 2.0 XML 系列(4):用XmlReader类介绍

    (本文摘自MSDN) XmlReader 类是一个提供对 XML 数据的非缓存.只进只读访问的抽象基类.该类符合 W3C 可扩展标记语言 (XML) 1.0 和 XML 中的命名空间的建议. XmlR ...

  5. 在ASP.NET 2.0中操作数据教程系列

    在ASP.NET 2.0中操作数据教程系列 Scott Mitchell最近完成了为 www.asp.net 网站撰写的<在ASP.NET 2.0中操作数据 (Working with Data ...

  6. [转]微软代码示例:ASP.NET 2.0 三层架构应用程序教程系列

    本文转自:http://www.codeusing.com/hi/uephee.wen/resource/view/170.aspx 资源分类:微软代码示例               更新日期:20 ...

  7. ASP.NET 2.0 之 Master Page 学习笔记 --zt

    如何使用 MasterPage 1. 创建 MasterPage,后缀名 .master, 如 x.master.     其中用 <asp:ContentPlaceHolder /> 定 ...

  8. ASP.NET MVC 3.0学习系列文章--Razor and ASP.NET MVC 3.0

    系列文章 ASP.NET MVC 3.0学习系列文章-序 Razor and ASP.NET MVC 3.0 ASP.NET MVC 3.0学习系列文章-Controllers in ASP.NET ...

  9. ASP.NET 2.0 之 Master Page 学习笔记

    如何使用 MasterPage 1. 创建 MasterPage,后缀名 .master, 如 x.master.     其中用 <asp:ContentPlaceHolder /> 定 ...

最新文章

  1. php获取循环,PHP循环获取GET和POST值的代码
  2. 【转】采用dlopen、dlsym、dlclose加载动态链接库
  3. ffplay.c学习-7-以音频同步为基准
  4. 微信红包API接口(PHP)
  5. 使用Maven程序集创建漏洞评估工件
  6. python2还是3好_学Python2还是python3 究竟哪个好
  7. java多张图片合成一张_一款国外有趣、简单、功能齐全的图片处理软件。
  8. 超分辨率分析(四)--Deep Image Prior
  9. PCWorld评出的2010年世界杀毒软件排名
  10. rss订阅_RSS订阅
  11. 比较两个路径的几种方式
  12. NFT新玩法丨一文了解将NFT所有权分割成ERC20代币的Fractional协议
  13. python 操作word页眉表格_pythondocx读写word文档:插入图片和表格,设置表格样式、章节、页眉、页脚等,Pythondocx,Word...
  14. 红色印章制作过程记录
  15. 跟小博老师一起学习数据库 ——索引
  16. SSE(Server-Sent Events)| 前后端demo参考
  17. 全连接网络和卷积神经网络对比分析
  18. java B2B2C Springcloud电子商务平台源码------Hystrix的缓存使用
  19. 女子手机流量一夜疯跑了50GB
  20. 成都java前景如何_成都从事java好就业吗?

热门文章

  1. LeetCode Best Time to Buy and Sell Stock with Cooldown(动态规划)
  2. C# delegate event
  3. docker中部署springboot项目,并且外部访问
  4. MySQL中函数CONCAT及GROUP_CONCAT
  5. 一天一种设计模式(一)------观察者模式
  6. 使用memcache的session入库
  7. 三亚之旅 海景--美得让你尖叫
  8. asp.net 获取 当前日期时间 及 前后N天日期时间(DropDownList数据绑定)
  9. 在.NET中获取一台电脑名,IP地址及当前用户名
  10. 使用opencv中的merge()函数为BGR图像添加alpha通道