今天有個朋友問這個問題,寫一下~
很簡單,只要在頁面的OnPreInit方法裏動態設置MasterPageFile 屬性爲當前站點的MasterUrl即可:
{
base.OnPreInit(e);
if (SPContext.Current != null)
Page.MasterPageFile = SPContext.Current.Web.MasterUrl;
}
在aspx裏就要這麼寫:
protected override void OnPreInit(EventArgs e)
{
base.OnPreInit(e);
this.MasterPageFile = base.Web.MasterUrl;
}
</script>
自己開發的頁面如果運行在SharePoint環境下也可這樣來實現母板頁的統一。