Is it possible to change the master-page of a content-page with the click of a button on that content-page?
If not why?
Master pages can be nested, with one master page referencing another as its master. Nested master pages allow you to create componentized master pages. For example, a large site might contain an overall master page that defines the look of the site.
It is possible, you'll have to override the OnPreInit method of your codebehind class like so...
protected override void OnPreInit(EventArgs e)
{
Page.MasterPageFile = "~/your/masterpage.master";
}
So to bind this to a click, you could use a query string parameter, i.e.
<a href="<%=Request.Url.ToString()%>?masterPage=alternative">Use
alternative master page</a>
And then in the codebehind
protected override void OnPreInit(EventArgs e)
{
if(Request["masterPage"] == "alternative")
{ Page.MasterPageFile = "~/your/alternative/masterpage.master"; }
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With