Page.MasterPageFile 属性

定义

获取或设置母版页的虚拟路径。Gets or sets the virtual path of the master page.

public:
 virtual property System::String ^ MasterPageFile { System::String ^ get(); void set(System::String ^ value); };
public virtual string MasterPageFile { get; set; }
member this.MasterPageFile : string with get, set
Public Overridable Property MasterPageFile As String

属性值

String

母版页面的虚拟路径。The virtual path of the master page.

例外

MasterPageFile 属性在 PreInit 事件完成后进行设置。The MasterPageFile property is set after the PreInit event is complete.

MasterPageFile 属性中指定的文件不存在。The file specified in the MasterPageFile property does not exist.

- 或 --or-

页中没有作为顶级控件的 Content 控件。The page does not have a Content control as the top level control.

注解

MasterPageFile属性是一个虚拟路径 (从与此页关联的母版页文件的应用程序) 的根目录中。The MasterPageFile property is a virtual path (from the root of the application) of the master page file associated with this page. MasterPageFile只能在事件中设置属性 PreInit ; 尝试在 MasterPageFile 事件之后设置属性 PreInit 将引发 InvalidOperationException 异常。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. 如果 MasterPageFile 属性无效, HttpException 则会在页面生命周期的后期引发类型的异常,但在事件中设置该属性时,不会引发异常 PreInitIf 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.

设置了属性的页 MasterPageFile 为内容页,因此只能包含控件的顶级控件 ContentPages that have the MasterPageFile property set are content pages, and therefore can contain only top-level controls that are Content controls.

适用于

另请参阅