To set an ASPNET master page dynamically, use the Page_PreInit function and set the Page.MasterPageFile property. For example:
protected void Page_PreInit(object sender, EventArgs e)
{
this.Page.MasterPageFile = "~/MasterPages/" + mymaster + ".Master";
}
In the above example, mymaster should be set by whatever your requirements dictate – read from DB/CMS/whatever. The page (aspx) itself shouldn’t have any other reference to the master page (ie, no “MasterPageFile attribute in the page directive), however it will still need the content placeholders, of course.