在内容页面中调用母版页控件

来源:互联网 发布:淘宝产品一键复制 编辑:程序博客网 时间:2024/05/22 12:07

在内容页面中调用母版页控件
1、在母版添加控件和属性
<asp:Label ID="Label1" runat="server"></asp:Label>
    public Label MasterPageLabel
    {
        get
        {
            return Label1;
        }
        set
        {
            Label1 = value;
        }
    }
2、先要在内容页面中添加
      <%@ MasterType VirtualPath="~/MasterPage22.master" %>

3、然后后台才能调用
    protected void Page_Load(object sender, EventArgs e)
    {
        Master.MasterPageLabel.Text = "现在时间:" + System.DateTime.Now.ToShortTimeString();
        Master.MasterPageLabel.Font.Size = 20;
    } 

原创粉丝点击