继承母板页的页面代码:

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeBehind="Default.aspx.cs" Inherits="MasterPageAp._Default" %>

一般的页面代码:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="MasterPageAp.WebForm1" %>

 

最大的区别是:MasterPageFile属性。

母版页中可以嵌套母版页

 

访问母版页控件和属性
1、使用Master.FindControl方法访问母版页上的控件
2、引用@MasterType指令访问母版页上的属性。

注意代码放置的位置:
在母版页的Page_load事件引发之前,内容页的Page_load事件已经引发,所以,此时从内容页中访问

母版页中的控件比较困难。本实例使用ASP.NET新增的Page_loadComplete事件,利用FindControl方

法来获取母版页的控件,其中,Page_LoadComplete事件是在生命周期内,网页加载结束时触发。当然

,还可以在Label控件的PreRender事件下完成此功能。

 

 

相关文章:

  • 2021-11-04
  • 2021-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-11
猜你喜欢
  • 2022-12-23
  • 2021-08-16
  • 2021-10-27
  • 2022-12-23
  • 2022-03-02
  • 2021-07-18
相关资源
相似解决方案