Asp.net中的母版页

    xiaoxiao2025-03-23  14

    1.母版页的主要功能是为Asp.net创建统一的用户界面和样式.

    2.机制:若第一次请求带有母版页的Page,则2个页面都进行编译.母版页合并到内容页的控件树中,内容页合并到母版页的ContentPlaceHolder中.最终,浏览器呈现的是合并页.

    一. 创建并使用母版页.

     1.当创建Web Form的时候,右下角有Select master page单选框,选上即可选择之前创建好的母版页(Master Page).   2.在母版页中适当的位置设置一个ContentPlaceHolder控件实现占位.   <asp:ContentPlaceHolder ID="MainContent" runat="server">     </asp:ContentPlaceHolder>  3.在aspx中包括代码头声明和Content控件.   <%@ Page Title="" Language="C#" MasterPageFile="~/MainMaster.master" AutoEventWireup="true"      CodeFile="Content.aspx.cs" Inherits="Content" %>     <asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">    注意:MasterPageFile和ContentPlaceHolderID 二. 使用Master,FindControl访问母版页的控件.  在aspx.cs中:   Label myLabel = (Label)this.Master.FindControl("nav_top2_log_span");     this.labContent.Text = myLabel.Text;     myLabel.Text = "您好!"; 三. 访问母版页上的公共属性.  在内容页代码头中加入:  <%@ MasterType VirtualPath="~/MainMaster.master" %>
    转载请注明原文地址: https://ju.6miu.com/read-1297324.html
    最新回复(0)