创建母版本页
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="SimpleMaster.master.cs"
Inherits="SimpleMaster" %>
<!DOCTYPE html PUBLIC "-//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 runat="server">
<style type="text/css">
html
{
background-color: Silver;
font: 14px Arial,Sans-Serif;
}
.content
{
margin: auto;
width: 700px;
background-color: White;
border: Solid 1px black;
}
.leftColumn
{
float: left;
padding: 5px;
width: 200px;
border-right: Solid 1px black;
height: 700px;
}
.rightColumn
{
float: left;
padding: 5px;
}
.clear
{
clear: both;
}
</style>
<title>Simple master</title>
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<div class="content">
<div class="leftColumn">
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
<div class="rightColumn">
<asp:ContentPlaceHolder ID="ContentPlaceHolder2" runat="server">
</asp:ContentPlaceHolder>
</div>
<br class="clear" />
</div>
</form>
</body>
</html>
----------------------------------------
<%@ Page Title="" Language="C#" MasterPageFile="~/SimpleMaster.master" %>
<script runat="server">
</script>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
SimpleContent
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
Content in the first column
<br />Content in the first column
<br />Content in the first column
<br />Content in the first column
<br />Content in the first column
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder2" Runat="Server">
Content in the Second column
<br />Content in the Second column
<br />Content in the Second column
<br />Content in the Second column
<br />Content in the Second column
</asp:Content>
嵌套母版本
SectionProducts.master
SectionServices.master
Products.aspx
Services.aspx
在母版页中使用图片和超链接
在母版页中使用相对URL必须十分小心。
使用ASP.net控件,相对URL会解析为相对于母版本的URL。
母版中添加Asp.net Image控件
<asp:Image ImageUrl="Picture.gif" run="server"/>
母版在MasterPages的文件夹中,则URL会解析为:/MasterPages/Pictrue.gif
即使内容页在一个完全不同的文件夹中,ImageUrl属性仍然会解析为相对于母版页的URL而不是相对于内容页的URL。
使用HTML标签,情况完全不同<a><img>
在母版中添加<img src="picture.gif"/>
内容页在ContentPages文件夹中则会解析为: /ContentPages/picture.gif
解决方法:
1、用ASP.Net控件替换使用相对URL的HTML元素
2、用绝对URL来替换相对URL 比较僵硬
3、在母版中使用方法来重新解析相对URL。 MasterUrl()
ImageMaster.master [in MasterPages文件夹]
ImageContent [在根目录下]
在Web配置文件中注册母版页
<configuration>
<system.web>
<pages masterPageFile="~/SimpleMaster.master"/>
</system.web>
</configuration>
母版页只能应用到内容页,如果一个页面没有Content控件,只是普通ASP.net页面的话,母版页被忽略。
2011-4-28 10:24 danny
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="SimpleMaster.master.cs"
Inherits="SimpleMaster" %>
<!DOCTYPE html PUBLIC "-//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 runat="server">
<style type="text/css">
html
{
background-color: Silver;
font: 14px Arial,Sans-Serif;
}
.content
{
margin: auto;
width: 700px;
background-color: White;
border: Solid 1px black;
}
.leftColumn
{
float: left;
padding: 5px;
width: 200px;
border-right: Solid 1px black;
height: 700px;
}
.rightColumn
{
float: left;
padding: 5px;
}
.clear
{
clear: both;
}
</style>
<title>Simple master</title>
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<div class="content">
<div class="leftColumn">
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
<div class="rightColumn">
<asp:ContentPlaceHolder ID="ContentPlaceHolder2" runat="server">
</asp:ContentPlaceHolder>
</div>
<br class="clear" />
</div>
</form>
</body>
</html>
----------------------------------------
<%@ Page Title="" Language="C#" MasterPageFile="~/SimpleMaster.master" %>
<script runat="server">
</script>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
SimpleContent
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
Content in the first column
<br />Content in the first column
<br />Content in the first column
<br />Content in the first column
<br />Content in the first column
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder2" Runat="Server">
Content in the Second column
<br />Content in the Second column
<br />Content in the Second column
<br />Content in the Second column
<br />Content in the Second column
</asp:Content>
嵌套母版本
<%@ Master Language="C#" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> </script> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <style type="text/css"> html { background-color: DarkGreen; font: 14px Georgia,Serif; } .content { width: 700px; margin: auto; border-style: solid; background-color: White; padding: 10px; } .tabstrip { padding: 3px; border-top: solid 1px black; border-bottom: solid 1px black; } .tabstrip a { font: 14px Arial; color: DarkGreen; text-decoration: none; } .column { float: left; padding: 10px; border-right: solid 1px black; } .rightColumn { float: left; padding: 10px; } .clear { clear: both; } </style> <title>My Site Master</title> </head> <body> <form id="form1" runat="server"> <div class="content"> <asp:Image ID="imgLogo" ImageUrl="~/Images/1.gif" AlternateText="Website Logo" runat="server" /> <div class="tabstrip"> <asp:HyperLink ID="lnkProducts" Text="Products" NavigateUrl="~/Products.aspx" runat="server" /> <asp:HyperLink ID="lnkServices" Text="Services" NavigateUrl="~/Services.aspx" runat="server" /> </div> <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server"> </asp:ContentPlaceHolder> <br class="clear" /> Copyright ©2010 by Danny. </div> </form> </body> </html>
SectionProducts.master
<%@ Master Language="C#" MasterPageFile="~/MySite.master" %> <script runat="server"> </script> <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server"> <div class="column"> <asp:ContentPlaceHolder ID="ContentPlaceHoder1" runat="server" /> </div> <div class="column"> <asp:ContentPlaceHolder ID="ContentPlaceHoder2" runat="server" /> </div> <div class="rightColumn"> <asp:ContentPlaceHolder ID="ContentPlaceHoder3" runat="server" /> </div> </asp:Content>
SectionServices.master
<%@ Master Language="C#" MasterPageFile="~/MySite.master" %> <script runat="server"> </script> <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server"> <div class="column"> <asp:ContentPlaceHolder ID="ContentPlaceHoder1" runat="server" /> </div> <div class="rightColumn"> <asp:ContentPlaceHolder ID="ContentPlaceHoder2" runat="server" /> </div> </asp:Content>
Products.aspx
<%@ Page Title="" Language="C#" MasterPageFile="~/SectionProducts.master" %> <script runat="server"> </script> <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHoder1" runat="Server"> Products,Products,Products <br /> Products,Products,Products <br /> Products,Products,Products <br /> Products,Products,Products <br /> Products,Products,Products </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHoder2" runat="Server"> Products,Products,Products 2 <br /> Products,Products,Products <br /> Products,Products,Products <br /> Products,Products,Products <br /> Products,Products,Products </asp:Content> <asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHoder3" runat="Server"> Products,Products,Products 3 <br /> Products,Products,Products <br /> Products,Products,Products <br /> Products,Products,Products <br /> Products,Products,Products </asp:Content>
Services.aspx
<%@ Page Title="" Language="C#" MasterPageFile="~/SectionServices.master" %> <script runat="server"> </script> <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHoder1" runat="Server"> Services,Services,Services 1 <br /> Services,Services,Services <br /> Services,Services,Services <br /> Services,Services,Services <br /> Services,Services,Services </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHoder2" runat="Server"> Services,Services,Services 2 <br /> Services,Services,Services <br /> Services,Services,Services <br /> Services,Services,Services <br /> Services,Services,Services </asp:Content>
在母版页中使用图片和超链接
在母版页中使用相对URL必须十分小心。
使用ASP.net控件,相对URL会解析为相对于母版本的URL。
母版中添加Asp.net Image控件
<asp:Image ImageUrl="Picture.gif" run="server"/>
母版在MasterPages的文件夹中,则URL会解析为:/MasterPages/Pictrue.gif
即使内容页在一个完全不同的文件夹中,ImageUrl属性仍然会解析为相对于母版页的URL而不是相对于内容页的URL。
使用HTML标签,情况完全不同<a><img>
在母版中添加<img src="picture.gif"/>
内容页在ContentPages文件夹中则会解析为: /ContentPages/picture.gif
解决方法:
1、用ASP.Net控件替换使用相对URL的HTML元素
2、用绝对URL来替换相对URL 比较僵硬
3、在母版中使用方法来重新解析相对URL。 MasterUrl()
ImageMaster.master [in MasterPages文件夹]
<%@ Master Language="C#" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> </script> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <asp:ContentPlaceHolder ID="head" runat="server"> </asp:ContentPlaceHolder> </head> <body> <form id="form1" runat="server"> <div> <img src='<%=Page.ResolveUrl("~/MasterPages/Logo.gif") %>' alt="Website Logo" /> <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server"> </asp:ContentPlaceHolder> </div> </form> </body> </html>
ImageContent [在根目录下]
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPages/ImageMaster.master" %> <script runat="server"> </script> <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server"> Head </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server"> <h1> Image Content</h1> </asp:Content>
在Web配置文件中注册母版页
<configuration>
<system.web>
<pages masterPageFile="~/SimpleMaster.master"/>
</system.web>
</configuration>
母版页只能应用到内容页,如果一个页面没有Content控件,只是普通ASP.net页面的话,母版页被忽略。
2011-4-28 10:24 danny
发表评论
-
19.5创建分层的SQL数据源控件
2011-06-01 09:18 837创建分层的SQL数据源控件 SqlHierarchicald ... -
19.4使用TreeView控件
2011-05-20 13:27 1216使用TreeView控件 1、声明式地添加树视图节点 Tr ... -
19.3使用Menu控件
2011-05-20 09:16 816使用Menu控件 1、声明式添加Menu条目 MenuHy ... -
7.3动态加载用户控件
2011-05-12 09:18 565动态加载用户控件 可以在运行时动态加载用户控件并将其显示在页 ... -
7.2Ajax和用户控件
2011-05-11 21:25 643Ajax和用户控件 RandomQuotation.ascx ... -
7.1创建用户控件
2011-05-11 13:15 585创建用户控件 简单例 ... -
6.4创建全局主题
2011-05-11 09:33 453创建全局主题 可以在一个Web服务器端上的多个程序之间共享同 ... -
6.3在主题中添加CSS
2011-05-10 21:22 483在主题中添加CSS 如果在主题文件夹中添加CSS文件,则在页 ... -
6.2在主题中添加皮肤
2011-05-10 09:09 873在主题中添加皮肤 一个主题可以包含一个或多个皮肤文件。可以通 ... -
6.1创建主题
2011-05-09 22:26 608创建主题 在名为App_Themes的应用程序的文件夹中新增文 ... -
5.3动态加载母版页
2011-05-09 12:50 724动态加载母版页 应用场合: 1)通过加载不同的母版页可以让网站 ... -
5.2修改母版页内容
2011-05-09 09:14 1223修改母版页内容 1、使用Title属性 <%@Pag ... -
4.1.3、上传大文件
2011-05-06 12:55 628上传大文件 上传大文件,需要做些处理 处理大文件时,需要使 ... -
4.1.2、文件保存到数据库
2011-05-06 09:13 4762、文件保存到数据库 上传 <%@ Page La ... -
4.1.1、文件保存到文件夹
2011-05-05 19:22 7042、文件保存到数据库 上传 <%@ Page Lan ... -
4.1接收上传文件
2011-05-05 09:14 575接收上传文件 FileUpload 控件属性 Enabled ... -
3.10创建自定义验证控件
2011-05-04 09:12 483创建自定义验证控件 BaseValidator类 抽象类 必 ... -
3.9使用ValidationSummary控件
2011-05-03 22:43 897使用ValidationSummary控件 在页面中的一处地 ... -
3.8使用CustomValidator控件
2011-05-03 11:21 609使用CustomValidator控件 CustomVali ... -
3.7使用RegularExpressionValidator控件
2011-05-02 19:02 654使用RegularExpressionValidator控件 ...
相关推荐
版本: 扫描版 出版社: 电子工业出版社书号: 9787121037726发行时间: 2007年02月01日 地区: 大陆 语言: 简体中文 简介: 内容简介: Pro/ENGINEER是美国PTC公司推出的一套从设计到制造的一体化三维设计软件,其...
Web服务器:IIS 5.1及以上版本 2.本书所附光盘范例 第1章(\Chapter 01) 示例描述:本章演示ASP.NET 2.0网站的预编译以及学习ASP.NET 2.0的前置知识。 WebSite文件夹 创建的ASP.NET 2.0 Web站点。 www文件夹...
5.1 装配基础 1、装配体引例--轮轴装配 2、自下而上的装配设计步骤 3、装配设计方法的类型 4、装配的基本概念 5、装配设计树 虚拟装配培训资料全文共62页,当前为第3页。 1、装配体引例--螺栓联接装配 (1)轴定位 ...
5.1选择对象.flv 5.2复制和移动图形对象.flv 5.3调整图形对象大小.flv 5.4构造对象.flv 5.5使用夹点编辑对象.flv 5.6通过双击编辑对象.flv 5.7 对象编组.flv 5.8综合实战——绘制古典窗户立面图.flv 5.9高手私房菜....
Web服务器:IIS 5.1及以上版本 2.本书所附光盘范例 第1章(\Chapter 01) 示例描述:本章演示ASP.NET 2.0网站的预编译以及学习ASP.NET 2.0的前置知识。 WebSite文件夹 创建的ASP.NET 2.0 Web站点。 www文件夹...
5.1、用途:搜索【模块自身未集成搜索功能】,仅展示属于某特定内容的表项 等 5.2、方法说明: 5.2.1、:列表_开启显示部分表项功能 参数:显示表项序号组【整数数组型】 可空(自带去重,可提供带重复序号...
5.1. 引用变量 5.2. 转义(\) 6. 退出和退出状态 7. Tests 7.1. Test结构 7.2. 文件测试操作 7.3. 其他比较操作 7.4. 嵌套的if/then条件test 7.5. 检查你的test知识 8. 操作符和相关的主题 8.1. 操作...
5.1. 引用变量 5.2. 转义(\) 6. 退出和退出状态 7. Tests 7.1. Test 结构 7.2. 文件测试操作 7.3. 其他比较操作 7.4. 嵌套的if/then 条件test 7.5. 检查你的test 知识 8. 操作符和相关的主题 8.1. 操作符 8.2. 数字...
IIS 5.1V Inertnet Explorer 6.0以上 3.2.2 工具简介 Dreamweaver MX 2004简介 Dreamweaver MX 2004 是 建立 Web 站点和应用程序的专业工具。 它将可视布局工具、应用程序开发功能和代码编辑支持组合为一个功能...
5.1 聚集 53 5.2 组成 54 5.3 组成结构图 54 5.4 接口和实现 55 5.5 接口和端口 58 5.5.1 可见性 58 5.5.2 作用域 59 5.6 小结 59 5.7 常见问题解答 60 5.8 小测验和习题 60 5.8.1 小测验 60 5.8.2 习题 60 第6章 ...