子页放置内容的容器:
<asp:content id="content1" contentPlaceHolder="ContentPlaceHolder1" runat="server"> <!--放置填充的内容--> </asp:content>1)调用母版中的方法及属性:在子页声明被母版页信息,然后直接用master.XXX()调用。
2)调用母版中的控件:在子页中通过FindControl搜索母版页的id,调用之。
母版页.aspx.cs(注意为public)
public void SayHi() { Response.Write("hello,man!"); }调用母版方法(调用属性一样),子页直接通过母版的方法名调用:
protected void Page_Load(object sender, EventArgs e) { Master.SayHello(); }调用母版中的控件(FindControl):
子页采用FindControl的方法(此处是通过按钮出发事件而将调用来的母版属性显示在Label中)
protected void btnGetMaster_Click(object sender, EventArgs e) { Label lbMaster = Master.FindControl("masterLabel") as Label; if (lbMaster != null) { Label2.Text = lbMaster.Text.ToString(); } }其实,母版可以存在多个子版块的形式,FindControl也将变换为,事实上上面的程序也是这种的简写
Label lbMaster = Master.FindControl(“ContentPlaceHolder1”) .FindControl(“Label1”) as Label;