System.Web.UI.MasterPageParser.GetCompiledMasterInstance C# (CSharp) Method

GetCompiledMasterInstance() public static method

public static GetCompiledMasterInstance ( string virtualPath, string inputFile, HttpContext context ) : MasterPage
virtualPath string
inputFile string
context System.Web.HttpContext
return MasterPage
		public static MasterPage GetCompiledMasterInstance (string virtualPath, string inputFile, HttpContext context)
		{
			return BuildManager.CreateInstanceFromVirtualPath (virtualPath, typeof (MasterPage)) as MasterPage;
		}

Usage Example

Example #1
0
        internal static MasterPage CreateMasterPage(TemplateControl owner, HttpContext context,
                                                    string masterPageFile, IDictionary contentTemplateCollection)
        {
            var req = context.Request;

            if (req != null)
            {
                masterPageFile = HostingEnvironment.VirtualPathProvider.CombineVirtualPaths(req.CurrentExecutionFilePath, masterPageFile);
            }
#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);
        }