System.Web.UI Namespace Page Class
.NET Framework version 2.0
Sets or retrieves the file name of the master page.
Inline |
<%@ Page masterpagefile = strMasterFileName ... %> |
Script |
[ string strMasterFileName = ] Page.MasterPageFile |
strMasterFileName |
The file name of the master page. |
The property is read/write with no default value.
Exception Type |
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 the name of the master page file associated with a content page.
The MasterPageFile property can be set declaratively using the @ Page directive.
<%@ Page Language="C#" MasterPageFile="~/pages/Master1.master" Title="Content Page" %>
<%@ Page Language="VB" MasterPageFile="~/pages/Master1.master" Title="Content Page" %> |
|
C# |
VB |
The MasterPageFile property can be set programmatically only in the PreInit event. Attempting to set the MasterPageFile property after the PreInit event will throw an InvalidOperationException exception.
NOTE: Pages that have the MasterPageFile property set are content pages, and therefore can contain only top-level controls that are Content controls.
Page Members MasterPage Class