母版页(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. android开发:Android 中自定义属性(attr.xml,TypedArray)的使用

    今天我们的教程是根据前面一节扩展进行的,如果你没有看,请点击 Android高手进阶教程(三)查看第三课,这样跟容易方便你的理解! 在xml 文件里定义控件的属性,我们已经习惯了android:att ...

  2. 算法笔记--字符串hash

    概述: 主要用于字符串的匹配. 定义hash函数: H(c)=(c1bm-1 +c2bm-2 +...+cmb0)mod h 对于字符串c中l-r区间的hash值: H(l,r)=H(1,r)-H(1 ...

  3. WPF自定义控件的两种方式

    方法A: 第一步:My自定义控件:Control 第二步:针对  “My自定义控件” 类型,编写<style>或<模板>(UI的外观完全由用户自己定义) 第三步: 使用My自定 ...

  4. python-day30--粘包

    一. 什么是粘包 1.须知:只有TCP有粘包现象,UDP永远不会粘包 2.所谓粘包问题主要还是因为接收方不知道消息之间的界限,不知道一次性提取多少字节的数据所造成的. 二.两种情况下会发生粘包. 1. ...

  5. seekg()/seekp()与tellg()/tellp()的用法详解

    本文转载于:http://blog.csdn.net/mafuli007/article/details/7314917 (在tcp的文件发送部分有应用) 对输入流操作:seekg()与tellg() ...

  6. python 爬取京东手机图

    初学urllib,高手勿喷... import re import urllib.request #函数:每一页抓取的30张图片 def craw(url,page): imagelist = []# ...

  7. dp练习(1)——马走日字

    3328: 马走日字 时间限制: 1 Sec  内存限制: 128 MB提交: 35  解决: 5[提交][状态][讨论版] 题目描述 一次外出旅游,你路上遇到了一个骑着马的强盗,你很害怕,你需要找一 ...

  8. view_baseInfo

    create view view_baseInfo as select c.spbh,c.tongym, c.spmch,c.shpgg,c.shpchd,a.pihao,a.pici,a.sxrq, ...

  9. 4. Median of Two Sorted Arrays *HARD* -- 查找两个排序数组的中位数(寻找两个排序数组中第k大的数)

    There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two ...

  10. PHP:第三章——PHP中表达式函数和匿名函数

    <?php header("Content-Type:text/html;charset=utf-8"); //表达式函数和匿名函数 /*$A=function(){ ech ...