开发者

Loading of Master pages dynamically?

开发者 https://www.devze.com 2023-01-31 13:03 出处:网络
Can we have th开发者_开发问答e Masterpage loaded dynamicallu. I have a page that must be used in 2 different scenarios ie., using two different master pages.

Can we have th开发者_开发问答e Masterpage loaded dynamicallu. I have a page that must be used in 2 different scenarios ie., using two different master pages.

Appreciate all your help.

Thanks,


in your page you can write

protected override void OnPreInit(EventArgs e)
{
    base.OnPreInit(e);
    this.Page.MasterPageFile = "~/AlternateMasterPage.master";
}

to change which one it will use


Yes you probably can, but it'll have to be rather early in the page life cycle if possible.

However, depending on what the "two different scenarios" are, you might be able to get away with one. For example, if you require showing/hiding controls (login, logout, etc) based on a user's authentication state (anonymous, authenticated, or in a particular role/group), then you might consider using a LoginView control instead. From a maintenance perspective, that might make things better if it still meets the requirements.

Edit: As per advice on the comment below - you would need to change the master page on the PreInit event.

0

精彩评论

暂无评论...
验证码 换一张
取 消