ASP.NET设置母版页
母版页允许开发人员创建具有指定的可编辑区域的站点级模板。随后,此模板可应用到网站中的 ASP.NET 页面上。这些 ASP.NET 页面只需为母版页中指定的可编辑区域提供相应内容 – 在使用母版页的所有 ASP.NET 页面中,母版页中的所有其它标记都相同。此模型允许开发人员定义并集中实现站点级页面布局。 因此,开发人员可以方便地为所有页面创建一致的外观,并进行轻松的更新。
简而言之:在一个网站上会有很多页面,并且有可能有的页面都有相同的部分,这样的话我们就可以将相同的部分制作成一个母版页,在多个页面进行调用,节省了代码的重复使用和开发效率。
开发过程:
新建两个html文件HtmlPage1.html,HtmlPage2.html,一个web窗体WebForm.aspx,一个web窗体用户控件WebUserControl1.ascx

第一种方式,利用纯html制作
1.首先我们先用静态html制作一个母版页,再利用iframe来显示母版页
HtmlPage1.html为母版页
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<style>
body{
margin:0px;
} #top{
width:%;
height:100px;
background-color:#6f5e5e;
}
.left{
float:left;
margin-top:12px;
margin-left:25px;
}
.logo{
margin-left:auto;
margin-right:auto;
margin-top:25px;
}
img{
vertical-align:middle;
}
.right{
float:right;
} </style>
</head> <body>
<div id="top">
<img src="img/leftcloud.png" class="left" />
<img src="img/logo.png" class="logo" />
<img src="img/rightcloud.png" class="right" />
</div>
</body>
</html>
HtmlPage2.html来调用
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head> <body style="margin:0px">
<iframe src="HtmlPage1.html" width="100%" height="100px"></iframe>
//利用iframe框架标签来显示
</body>
</html>
第二种方式利用ASP.NET制作
分别利用iframe框架标签和调用web用户控件来显示
用web用户控件制作母版页,因为测试所以代码跟HtmlPage1.html基本一样
web窗体用户控件WebUserControl1.ascx代码
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="WebUserControl1.ascx.cs" Inherits="WebApplication3.WebUserControl1" %>
<style>
body{
margin:0px;
} #top{
width:%;
height:100px;
background-color:#6f5e5e;
}
.left{
float:left;
margin-top:12px;
margin-left:25px;
}
.logo{
margin-left:auto;
margin-right:auto;
margin-top:25px;
}
img{
vertical-align:middle;
}
.right{
float:right;
} </style> <div id="top">
<img src="img/leftcloud.png" class="left" />
<img src="img/logo.png" class="logo" />
<img src="img/rightcloud.png" class="right" />
</div>
web窗体WebForm1.aspx调用代码
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication3.WebForm1" %> <%@ Register Src="~/WebUserControl1.ascx" TagPrefix="uc1" TagName="WebUserControl1" %> <!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>
</head>
<body style="margin:0px">
<!--两种方式嵌入不需要改变的网页显示部分-->
<iframe src="HtmlPage1.html" width="100%" height="100px"></iframe> <!--iframe 框架标签--> <form id="form1" runat="server">
<uc1:WebUserControl1 runat="server" id="WebUserControl1" />
<!--web窗体用户控件-->
</form>
</body>
</html>
asp调用web窗体用户控件很简单,你着需要从解决方案那里把用户控件拖到代码区就行了,厉害吧
ASP.NET设置母版页的更多相关文章
- pages 元素(ASP.NET 设置架构)web.config 详解
pages 元素(ASP.NET 设置架构) buffer="[True|False]" enableEventValidation="[True|False] ...
- 【配置】检测到在集成的托管管道模式下不适用的ASP.NET设置的解决方法(非简单设置为【经典】模式)。
× 检测到在集成的托管管道模式下不适用的ASP.NET设置的解决方法(非简单设置为[经典]模式). 我们将ASP.NET程序从IIS6移植到IIS7,可能运行提示以下错误: HTTP 错误 5 ...
- 检测到在集成的托管管道模式下不适用的ASP.NET设置的解决方法(转)
我们将ASP.NET程序从IIS6移植到IIS7,可能运行提示以下错误: HTTP 错误 500.23 - Internal Server Error 检测到在集成的托管管道模式下不适用的 ASP.N ...
- HTTP 错误 500.23 - Internal Server Error 检测到在集成的托管管道模式下不适用的 ASP.NET 设置。
检测到在集成的托管管道模式下不适用的ASP.NET设置的解决方法(非简单设置为[经典]模式). - CatcherX 2014-03-11 11:03 27628人阅读 评论(2) 收藏 举报 分类 ...
- ASP.NET 之 检测到在集成的托管管道模式下不适用的ASP.NET设置
将ASP.NET程序从IIS6移植到IIS7后,调试运行可能提示以下错误: HTTP 错误 500.23 - Internal Server Error 检测到在集成的托管管道模式下不适用的 ASP. ...
- asp.net C#母版页和内容页事件排版载入顺序生命周期
asp.net C#母版页和内容页事件排版载入顺序生命周期 关于ASP页面Page_Load发生在事件之前而导致的问题已经喜闻乐见,对于问题的解释也非常全面.可是怎样解决这个问题则较少有人说明,我就再 ...
- 2014-07-31 ASP.NET的母版页使用
今天是在吾索实习的第17天.我在这天主要负责系统的骨架的搭建.首当其冲,要用的知识点就是ASP.NET母版页的使用了. ASP.NET的母版页有两种:一种是MasterPage,最常用也是最普通的母版 ...
- (转)检测到在集成的托管管道模式下不适用的ASP.NET设置的解决方法(转)
我们将ASP.NET程序从IIS6移植到IIS7,可能运行提示以下错误: HTTP 错误 500.23 - Internal Server Error 检测到在集成的托管管道模式下不适用的 ASP.N ...
- roleManager 元素(ASP.NET 设置架构),我是因为SSL弱密码(转)
为角色管理配置应用程序. 此元素是 .NET Framework 2.0 版中的新元素. configuration 元素(常规设置架构) system.web 元素(ASP.NET 设置架构) ...
随机推荐
- SoapUI Properties的使用
Link:http://testautomationnoob.blogspot.com/2012/10/soapui-properties-and-property-related.html soap ...
- http转https的各种应用
http://www.lccee.com/content-57.html https://www.gworg.com/ssl/127.html apach: LoadModule socache_sh ...
- redis备份恢复
redis的几种数据导入导出方式[转] 环境说明:202.102.221.11 redis源实例202.102.221.12 redis目标实例202.102.221.13 任意linux系统 一 ...
- bean copy
最初采用apache beanutils,性能很低.后来转为hutool,但不能复制指定格式的日期,所以采用性能很高的com.github.yangtu222.BeanUtils 它已经实现了 cop ...
- SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape错误原因及解决方法
用Python打开文件: with open('C:\Users\PINPIN\test\file1.txt','r') as f2: pass 运行后直接就报错了: File "<i ...
- thinkPHP5.0验证码不显示
1.使用composer安装时,验证码无法正常显示 主要是因为验证码扩展库的版本安装不正常,官方的5.0版本的扩展库版本号都是1.*,默认安装的是2.0版本,2.0版本均为ThinkPHP5.1版本专 ...
- ubuntu replace system openjdk
一些ubuntu自带jdk的.但是有时候会确实我们所要的文件.下面介绍如何replace jdk 1. 卸载现有jdk sudo apt-get purge openjdk-\* 2. 下载jdk. ...
- vue interceptors 设置请求头
在main.js添加过滤器,可以 Vue.http.interceptors.push((request,next)=>{ //request.credentials = true; // 接口 ...
- Docker Ubuntu/CentOS 下运行 java jar
官方安装方法 https://docs.docker.com/engine/installation/linux/ubuntu/ Ubuntu安装包 https://download.docker.c ...
- PHP速学
基本代码 <?php echo "Hello world";?> 变量定义 <?php $a=true; $bool_value=true; $integer_v ...