母版页的使用(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"-->
显示效果
相关文章推荐
- 去掉NSString中的HTML标签
- web移动开发最佳实践之html篇
- 第一个自定义HTML网页
- Html中tr th 和 tr td的区别
- web MVC程序开发增删改查参考代码。思路是面向对象思想,以及在HTML代码中嵌入C#代码
- 在HTML中优雅的生成PDF
- Html 加载音乐代码mp3
- html中链接<a>------------如何设置空链接或者无效链接
- Web之旅第一站——HTML
- html运用(一) 如何将一个HTML页面嵌套在另一个页面中
- HTML Form表单详解
- 学习html(8)
- gcov、lcov与genhtml 使用心得
- HTML代码简写法:Emmet和Haml
- 从后台action传过来的字符串不能被解析html代码 解决办法和struts2 里escape="false"的问题
- 常用特殊符号的HTML代码(HTML字符实体)
- html canvas svg 学习
- HTML规范 - 邮件内容
- HTML规范 - 内容语义
- HTML规范 - 代码格式