internal static MasterPage CreateMasterPage (TemplateControl owner, HttpContext context,
string masterPageFile, IDictionary contentTemplateCollection)
{
#if TARGET_JVM
MasterPage masterPage = MasterPageParser.GetCompiledMasterInstance (masterPageFile,
owner.Page.MapPath (masterPageFile),
context);
#else
MasterPage masterPage = BuildManager.CreateInstanceFromVirtualPath (masterPageFile, typeof (MasterPage)) as MasterPage;
#endif
if (masterPage == null)
throw new HttpException ("Failed to create MasterPage instance for '" + masterPageFile + "'.");
if (contentTemplateCollection != null) {
foreach (string templateName in contentTemplateCollection.Keys) {
if (masterPage.ContentTemplates [templateName] == null)
masterPage.ContentTemplates [templateName] = contentTemplateCollection[templateName];
}
}
masterPage.Page = owner.Page;
masterPage.InitializeAsUserControlInternal ();
List <string> placeholders = masterPage.placeholders;
if (contentTemplateCollection != null && placeholders != null && placeholders.Count > 0) {
foreach (string templateName in contentTemplateCollection.Keys) {
if (!placeholders.Contains (templateName.ToLowerInvariant ())) {
throw new HttpException (
String.Format ("Cannot find ContentPlaceHolder '{0}' in the master page '{1}'",
templateName, masterPageFile));
}
}
}
return masterPage;
}