当前位置: 移动技术网 > IT编程>开发语言>.net > ASP.NET母版页基础知识介绍

ASP.NET母版页基础知识介绍

2017年12月12日  | 移动技术网IT编程  | 我要评论

2018年国考职位表查询,硬盘安装win7,五行健康体操的好处

模板页是做什么的?

利用模板页可以方便快捷的创建统一风格的asp.net网站,并且容易管理和维护,提高了效率。
模板页为网页定义所需要的外观和标准,在母版的基础上创建包含显示内容的各个内容页。当用户请求内容页时,这些内容页与母版页合并,这样,模板页的布局与内容页的布局就可以组合在一起输出了。

模板页一般用来:

1、通过修改模板页来处理网页的通用功能。
2、可以方便的创建一组控件和代码,并应用于一组网页。
3、通过允许控制占位符控件的呈现方式,模板页可以在细节上控制最终页的布局。

模板页与普通页

我们在vs中建立一个模板页,可以看到不同于一般的内容的地方:
@master替换了@page,包含了多个可替换的占位符contentplaceholder.

普通页面和母版页面进行关联:

 普通页面的属性,masterpagefile,就会给出提示来选择使用的母版页,或是在新建页面的时候选择使用母版页,也可以把一个母版页应用到普通页面上。
demo:

模板页代码:

<%@ master language="c#" autoeventwireup="true" codefile="masterpage2.master.cs"inherits="模板页_masterpage2"%> 
 
  
 
<!doctype htmlpublic "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> 
 
  
 
<html xmlns="http://www.w3.org/1999/xhtml"> 
 
<head id="head1" runat="server"> 
 
  <title>模板页面</title> 
 
  <asp:contentplaceholderidasp:contentplaceholderid="head" runat="server"> 
 
  </asp:contentplaceholder> 
 
</head> 
 
<body style="height: 141px; width:747px"> 
 
  <form id="form1" runat="server"> 
 
  <div> 
 
  </div> 
 
  <p> 
 
    </p> 
 
  <table style="width: 102%; height: 126px;"> 
 
    <tr> 
 
      <td> 
 
        网站的log、搜索人数,登录人数,站点导航的信息等。</td> 
 
      <td> 
 
        </td> 
 
      <td> 
 
        </td> 
 
    </tr> 
 
    <tr> 
 
      <td> 
 
    <asp:contentplaceholderidasp:contentplaceholderid="contentplaceholder1" runat="server"> 
 
     
 
    </asp:contentplaceholder> 
 
      </td> 
 
      <td> 
 
        </td> 
 
      <td> 
 
        </td> 
 
    </tr> 
 
    <tr> 
 
      <td> 
 
        底部版权信息等。</td> 
 
      <td> 
 
        </td> 
 
      <td> 
 
        </td> 
 
    </tr> 
 
  </table> 
 
  </form> 
 
</body> 
 
</html> 

内容页代码:

<%@ page title="" language="c#" masterpagefile="~/模板页/masterpage2.master" autoeventwireup="true"codefile="contentpage.aspx.cs"inherits="contentpage" %> 
<asp:contentidasp:contentid="content1" contentplaceholderid="head"runat="server"> 
 
</asp:content> 
 
<asp:contentidasp:contentid="content2" contentplaceholderid="contentplaceholder1"runat="server"> 
 
  <p> 
 
  添加内容页面</p> 
 
</asp:content> 

显示: 

 关于母版页和主题:

和ppt中母版和主题一样的。是这样的:
利用模板可以在它的基础上添加自己的内容就可以了,相当于做好的框架、风格等。母版相当于是组件,需要自己搭这个框架、风格等。母版是我们从众多类似的结构网页中把相同不变的部分抽象出来,并可以运用到更多网页中,节省时间。

这个简单的例子是不是帮助大家更好的理解了母版页的使用方法了,希望大家会继续关注小编分享的文章。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网