博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

MasterPage 的使用方法

Posted on 2006-11-22 22:57  孤峰皓月  阅读(921)  评论(0编辑  收藏  举报

MasterPage 的几个知识点:
1. 在母版页中的 ContentPlaceHolder ,相应的内容页显示为:Content
2. 母版页与内容页的数据通信:每一个控件都得找,
例如:((Label)Master.FindControl("label1")).Text ="MasterPage级别的:"+ DropDownList1.SelectedValue;
前面的label1是 母版页中的, 后面的 DropDownList1 是在内容页中,这句代码是写在 内容页的 cs 文件中.
3. 如果要改变 母版, 则应该在 内容页与母版页合并之前,改变母版页文件.方法如下
     MasterPageFile="~/TestMasterPage.master"
    过程是这样的:内容页根据页头的 MasterPageFile="~/TestMasterPage.master" 找到母版页后,再合并后在前台显示出来
     private void Page_PreInit(object sender,EventArgs e)
     {
         if (Session["jiao"] == "")
           { //切换 母版页 
                 Page.MasterPageFile = "/TestMasterPage.master"; 
           }
     }
4.  母版页还可以镶嵌使用.这里没做.

母版前台页面:  testMasterPage.master



内容页前台:

内容页后台: