I know the following will set the master page programmatically in an ASP.NET VB.NET application:
Me.MasterPageFile = "~/masterPage.master"
Is it possible to programmatically set a master page file that would apply to all pages across an application, instead of having to set it for each individual page? I want to be able to retrieve this value from a database in order to set the master page file to use.
If not, is it possible to set more than one master page file in the web.config?
This is what You can do with ASP.NET C#. I didnt test it with VB.
Declare Your own page class and set master page there for all Your pages:
public class MyPage : System.Web.UI.Page
{
void Page_PreInit(Object sender, EventArgs e)
{
this.MasterPageFile = "MasterPage.master";
}
}
Inherit from Your own page class for each page that You create:
public partial class _Default : MyPage
{
}
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