简体   繁体   中英

Can I use the same content page with two different master pages?

I have an asp.net content page which is used inside of a master page (with header, menu and some links). I would like to reuse it in a different context without the master page (to not display the header and menu there), or with an empty master page if this is somehow possible. I don't want to violate DRY principle by taking the whole page and creating a standalone clone of it for obvious reasons. Is this somehow possible ?

Yes, you can set the master page dynamically in the content pages Page_PreInit method:

private void Page_PreInit(object sender, EventArgs e)
{
    this.MasterPageFile = "MyMasterPage.master"
}

Set up some logic to dynamically choose which master page filename to pass in, and you are now sharing one content page with many master pages.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM