Page.MasterPageFile Property
Updated: May 2011
Gets or sets the virtual path of the master page.
Assembly: System.Web (in System.Web.dll)
| Exception | Condition |
|---|---|
| InvalidOperationException | The MasterPageFile property is set after the PreInit event is complete. |
| HttpException | The file specified in the MasterPageFile property does not exist. - or - The page does not have a Content control as the top level control. |
The MasterPageFile property is a virtual path (from the root of the application) of the master page file that is associated with this page. The MasterPageFile property can be set only in the PreInit event; attempting to set the MasterPageFile property after the PreInit event will throw an InvalidOperationException exception. If the MasterPageFile property is not valid, an exception of type HttpException is thrown later in the page life cycle, but no exception is thrown when the property is set in the PreInit event.
Pages that have the MasterPageFile property set are content pages, and therefore can contain only top-level controls that are Content controls.
| Topic | Location |
|---|---|
| How to: Reference ASP.NET Master Page Content | Building ASP .NET Web Applications |
| How to: Reference ASP.NET Master Page Content | Building ASP .NET Web Applications |
| How to: Create Content Pages for an ASP.NET Master Page (Visual Studio) | Building ASP .NET Web Applications in Visual Studio |
| How to: Reference ASP.NET Master Page Content |
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.