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 ?
Sounds reasonable, I'll probably go this way, thanks. The only problem is that I have to transform the already existing page to a control, but hopefully that's not too much work..
Thomas Wanner
2010-02-15 10:09:55
+3
A:
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.
Moo
2010-02-15 10:10:17
I was thinking the same thing! Then there's no need to convert existing pages to a control.
Pieter Nijs
2010-02-15 10:16:46