protected IRoot RootMaster { get; set; } protected void Page_PreInit(object sender, EventArgs e) { if (RequestHelper.GetBoolean("fromABC")) { Page.MasterPageFile = "~/ABC/Root.master"; RootMaster = Master as ABC.Root; } else { RootMaster = Master as Root; } }
如上,在 Page_PreInit 中,通过参数,来调整 Page.MasterPageFile。
由于我们还要访问母版,所以还要切换母版类,为了两个母版类兼容,我们必须使用接口。
另: “MasterPageFile”属性只能在“Page_PreInit”事件之中或之前设置。