如何使Layouts里的页面应用站点母板页

来源:互联网 发布:云计算上市公司龙头 编辑:程序博客网 时间:2024/06/07 12:06

今天有个朋友问这个问题,写一下~

很简单,只要在页面的OnPreInit方法里动态设置MasterPageFile 属性为当前站点的MasterUrl即可: 

protected override void OnPreInit(EventArgs e)
    {
        
base.OnPreInit(e);

        
if (SPContext.Current != null)
            Page.MasterPageFile 
= SPContext.Current.Web.MasterUrl;
    }

 

在aspx里就要这么写: 

<script runat="server">
    
    protected override 
void OnPreInit(EventArgs e)
    {
        base.OnPreInit(e);
        
this.MasterPageFile = base.Web.MasterUrl;
    } 
    
</script>

 

 自己开发的页面如果运行在SharePoint环境下也可这样来实现母板页的统一。

原创粉丝点击