您的位置:首页 > Web前端 > HTML

母版页的使用(shtml)

2015-07-07 19:59 513 查看

使用母版页

1.网页很多地方长得一样,也有不一样的地方,Webform的母版页(MasterPage),使用母版页的窗体。

2.母版页太笨重。(加载母版页,然后进行多次填坑,麻烦!)

3.母版页使用ContentPlaceHolder挖坑,“使用母版页的窗体”用Content填坑

案例—1

新建一个母版页peo.Master

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="peo.master.cs" Inherits="wj.peo" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">

</asp:ContentPlaceHolder>
</div>
</form>
<asp:ContentPlaceHolder ID="contentplaceholder2" runat="server">

</asp:ContentPlaceHolder>
</body>
</html>


新建使用母版页的Web窗体

<%@ Page Title="" Language="C#" MasterPageFile="~/peo.Master" AutoEventWireup="true" CodeBehind="muban1`.aspx.cs" Inherits="wj.muban1_" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<!--这里在模板页的第一个位置写内容-->
<script type="text/javascript">

alert("欢迎进入本网页!");
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
姓名:<input type="text" id="name"/>
<br />
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="contentplaceholder2" runat="server">
北京|如鹏|传智|博客
</asp:Content>


推荐使用shtml轻量级母版页

4.Shtml:ServerSideInclude(SSI),主流web服务器(iis、apache等)都支持。效率高,不需要经过asp.net处理,轻量级。


<!--#include file="info.htm"-->


****服务器拼接****好页面之后就直接发送到了浏览器端了。而且服务器用了缓存技术,将拼接好的页面,缓存一段时,加快了访问时间。


案例—shtml

新建一个头html head.html

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
关于我们|如鹏|上海|天津|河南
<br />


新建一个尾html foot.html

<br />
友情链接|荣誉|地址|北京大学|上海大学

</body>
</html>


新建一个1.shtml调用“头”,“尾”文件,在服务器中拼接

<!--#include file="head.html"-->
<br />
<br />
我是shtml的主要部分
<br />
<br />
<!--#include file="foot.html"-->


显示效果

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: