2017-5-25 母版页
Posted Zoe
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了2017-5-25 母版页相关的知识,希望对你有一定的参考价值。
母版页:
可以把界面的部分代码进行重用
母版页的基础使用:
二级母版页的使用:
母版页与子页之间数据的传递:
母版页公共的外部样式表路径和外部JS文件的路径匹配:css文件可以直接引用,js文件需要写一个方法
public string abc()
{
return ResolveClientUrl("javascript.js");
}
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server"> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> <h1>这是页面1,我们套用母版页出来的页面</h1> </asp:Content>
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } }
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.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>这是页面2,是我们套用母版页出来的第二个页面</h1> </asp:Content>
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class Default2 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } }
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage2.master" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %> <asp:Content ID="Content1" ContentPlaceHolderID="mp2_content1" Runat="Server"> <h1>这里是我们套用二级母版页出来的页面</h1> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:Button ID="Button1" runat="server" Text="Button" /> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> </asp:Content>
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) { string s = TextBox1.Text; Label1.Text = s; MasterPage2 m2 = this.Master as MasterPage2; m2.aaa(s); } }
alert("aaaaa");
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %> <!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> <style type="text/css"> * { padding:0px; margin:0px; } .header { width:100%; height:100px; background-color:orange; } .footer { width:100%; height:200px; background-color:black; } </style> <asp:ContentPlaceHolder id="head" runat="server"> </asp:ContentPlaceHolder> </head> <body> <form id="form1" runat="server"> <div> <div class="header"> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> </div> <asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server"> </asp:ContentPlaceHolder> <div class="footer"></div> </div> <script src="<%=abc() %>"></script> </form> </body> </html> <%--<script src="JavaScript.js"></script>--%>
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class MasterPage : System.Web.UI.MasterPage { protected void Page_Load(object sender, EventArgs e) { } public void aa(string a) { TextBox1.Text = a; } public string abc() { return ResolveClientUrl("JavaScript.js"); } }
<%@ Master Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="MasterPage2.master.cs" Inherits="MasterPage2" %> <asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server"> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> <div style="width:30%;float:left;height:500px;background-color:green;"> 这是一条菜单选项<br /><br /> 这是一条菜单选项<br /><br /> 这是一条菜单选项<br /><br /> 这是一条菜单选项<br /><br /> 这是一条菜单选项<br /><br /> 这是一条菜单选项<br /><br /> 这是一条菜单选项<br /><br /> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> </div> <div style="width:70%;float:left;height:500px;background-color:yellow;"> <asp:ContentPlaceHolder ID="mp2_content1" runat="server"></asp:ContentPlaceHolder> </div> <div style="clear:both"></div> </asp:Content>
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class MasterPage2 : System.Web.UI.MasterPage { protected void Page_Load(object sender, EventArgs e) { } public void aaa(string a) { TextBox1.Text = a; MasterPage m = this.Master as MasterPage; m.aa(a); } }
以上是关于2017-5-25 母版页的主要内容,如果未能解决你的问题,请参考以下文章