现在的位置: 首页 > 综合 > 正文

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

2012年08月01日 ⁄ 综合 ⁄ 共 495字 ⁄ 字号 评论关闭

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

很简单,只要在页面的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环境下也可这样来实现母板页的统一。

 

抱歉!评论已关闭.