母版页(Master Pages)为网站内的其他页面提供模版。

Master Page 使您有能力为 web 应用程序中的所有页面(或页面组)创建一致的外观和行为。

Master Page 为其他页面提供了模版,带有共享的布局和功能。Master Page 为内容定义了可被内容页面覆盖的占位符。而输出结果就是 Master Page 和内容页面的组合。

内容页包含您希望显示的内容。

当用户请求内容页时,ASP.NET 会对页面进行合并以生成输出,输出结果对 Master Page 的布局和内容页面的内容进行了合并。

=======================================================================================================

导航和页脚母页版

MP1.master:
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MP1.master.cs" Inherits="MP1" %>

<!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>
<link href="csss/css1.css" rel="stylesheet" />
<script src="<%=abc() %>"></script>//解决JS文件路径不统一的问题
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<div> <div id="header">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</div> <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder> <div id="footer"></div> </div>
</form>
</body>
</html>

MP1.master.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls; public partial class MP1 : System.Web.UI.MasterPage
{
public void mp1_aaa(string s)
{
TextBox1.Text = s;//接收传值
} public string abc()
{
return ResolveClientUrl("js/js1.js");
} protected void Page_Load(object sender, EventArgs e)
{ }
}

嵌入了mp1的左标签母页版

MP2.master.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls; public partial class MP2 : System.Web.UI.MasterPage
{
public void aaa(string s)
{
TextBox1.Text = s; MP1 mp1 = this.Master as MP1;//传值
mp1.mp1_aaa(s); } protected void Page_Load(object sender, EventArgs e)
{ }
}

MP2.master

<%@ Master Language="C#" MasterPageFile="~/MP1.master" AutoEventWireup="true" CodeFile="MP2.master.cs" Inherits="MP2" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">

    <style>
#left {
position: relative;
width: %;
height: 300px;
background-color: yellow;
float: left;
} #right {
position: relative;
width: %;
height: 300px;
background-color: aqua;
float: left;
}
</style> </asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server"> <div id="left">
这里是标题1<br />
<br />
这里是标题1<br />
<br />
这里是标题1<br />
<br />
这里是标题1<br />
<br />
这里是标题1<br />
<br />
这里是标题1<br />
<br />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> </div>
<div id="right"> <asp:ContentPlaceHolder ID="MP2_Content" runat="server"></asp:ContentPlaceHolder> </div>
<div style="clear: both;"></div>
</asp:Content>

这里是MP1掏出来的第二个页面

<%@ Page Title="" Language="C#" MasterPageFile="~/MP1.master" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> <h1>这里是MP1掏出来的第二个页面</h1> </asp:Content>

这里是MP2套出来的页面

<%@ Page Title="" Language="C#" MasterPageFile="~/MP2.master" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>

<asp:Content ID="Content1" ContentPlaceHolderID="MP2_Content" Runat="Server">

    <h1>这里是MP2逃出来的页面11111</h1>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" /> </asp:Content>

mp2套出来的页面.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls; public partial class Default3 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Button1.Click += Button1_Click;
} void Button1_Click(object sender, EventArgs e)
{
//1、把本页面中的文本框的值取出来
string s = TextBox1.Text; //2、把取出来的值放到母版页的文本框中去
MP2 mp2 = this.Master as MP2;
mp2.aaa(s); }
}

Webform---母版页(Master Pages)的更多相关文章

  1. ASP.NET MVC- VIEW Creating Page Layouts with View Master Pages Part 4

    In this tutorial, you learn how to create a common page layout for multiple pages in your applicatio ...

  2. 【2017-05-25】WebForm母版页

    母版页:可以把界面的部分代码进行重用 添加新项-母版页 在母版页中界面代码不要写在 <asp:ContentPlaceHolder ID="head" runat=" ...

  3. WebForm母版页

    母版页:可以把界面的部分代码进行重用 添加新项-母版页 在母版页中界面代码不要写在 <asp:ContentPlaceHolder ID="head" runat=" ...

  4. 使用 AngularJS 开发一个大规模的单页应用(SPA)

      本文的目标是基于单页面应用程序开发出拥有数百页的内容,包括认证,授权,会话状态等功能,可以支持上千个用户的企业级应用. 下载源代码 介绍 (SPA)这样一个名字里面蕴含着什么呢? 如果你是经典的S ...

  5. mvc 母版页、用户自定义控件

    母版页(Master) 1.母版页是与Controller无关的,母版页只是一个View文件,而没有任何Controller与之相对应. 2.其实在ASP.NET MVC中View的aspx与母版页并 ...

  6. 使用SharePoint 2010 母版页

    SharePoint 2010母版页所用的还是ASP.NET 2.0中的技术.通过该功能,实现了页面框架布局与实际内容的分离.虽然在本质上自定义母版页的过程和以前版本的SharePoint大致相同,但 ...

  7. 转载 SharePoint 2013配置Master Page and Page Layout

    转载原地址: http://www.cnblogs.com/huangjianwu/p/4539706.html 涉及到的内容是关于SharePoint 2013如何部署自定义的母版页和布局页. 进入 ...

  8. MVC与WebForm的简单的比较

    MVC与WebForm的简单的比较 ASP 强制程序员将业务逻辑和展示页放到一个文件中 WebForm 允许程序员将业务逻辑与页面展示分开到不同的文件中,并且提供强大的开发平台来写  业务逻辑代码  ...

  9. SharePoint 2013 Deploy Master Page And Page Layout

    2013年9月27日的一篇随笔,其实也是自己编写的部署文档,由于客户是HK的,所以描述部分是用英文. 涉及到的内容是关于SharePoint 2013如何部署自定义的母版页和布局页. First, L ...

随机推荐

  1. js 数组的删除

    var test=[1,2,1,2,3,4,5,6,7]; 1.remove test.remove(1)     位置 test.remove(-2) test.remove(2,3) 2 dele ...

  2. 【Android】查看包名和首启动activity

    工具:aapt 位置:$ANDROID_HOME/build-tools/版本号/aapt 需要配置环境变量才能使用 aapt dump badging XXXapk 输出信息中重要的有: packa ...

  3. Failed to execute operation: No such file or directory(systemctl enable iptables.service)

    在保存Iptables配置时:systemctl enable iptables.service 出现错误: Failed to execute operation: No such file or ...

  4. 一个登陆浏览api接口; 其他相关: Form_with参数的不同写法; 简单使用curl。

    eeting-up app: 完成一个需求: 完成:https://github.com/chentianwei411/meeting-up-app 第四步实现API接口 Add api base a ...

  5. Java基础-IO流(13)

    IO流用来处理设备之间的数据传输.可以实现文件复制,上传文件和下载文件. Jdk提供的流继承了四大类:InputStream(字节输入流),OutputStream(字节输出流),Reader(字符输 ...

  6. IE6不兼容postion:fixed已解决

    将要设置postion:fixed的元素的css中添加以下代码: //如果想要是头部悬停,则以下代码即可. .customService{        position: fixed;bottom: ...

  7. 『科学计算』通过代码理解线性回归&Logistic回归模型

    sklearn线性回归模型 import numpy as np import matplotlib.pyplot as plt from sklearn import linear_model de ...

  8. C# / .NET 在类中使用Server.MapPath

    直接在类中使用 Server.MapPath 会出现错误,这是由于类中不能直接使用 System.Web.UI.Page 的非静态函数造成的.解决方法有两种: 方法一.使类继承System.Web.U ...

  9. Sql Server约束的学习二(检查约束、默认约束、禁用约束)

    接上一篇的Sql Server约束学习一(主键约束.外键约束.唯一约束) 4.检查约束 1)检查约束的定义 检查约束可以和一个列关联,也可以和一个表关联,因为它们可以检查一个列的值相对于另一个列的值, ...

  10. POJ 2752 KMP中next数组的理解

    感觉这里讲的挺好的.http://cavenkaka.iteye.com/blog/1569062 就是不断递归next数组.长度不断减小. 题意:给你一个串,如果这个串存在一个长度为n的前缀串,和长 ...