开发者

Loading of Master pages dynamically?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜