在项目中添加页面时无法查看母版页

时间:2012-03-21 09:53:19

标签: asp.net

我正在尝试在项目中添加.aspx页面,但在添加.aspx页面时,我无法选择现有的母版页。

2 个答案:

答案 0 :(得分:2)

不知道为什么它不可见;如果您无法设置,只需稍后手动将其添加到您网页的@Page directive

很简单:

MasterPageFile="~/Path/To/My/MasterPage.master" 

E.g。在ASPX页面上,写下如下内容:

<%@ Page 
    Culture="auto"
    UICulture="auto"
    MaintainScrollPositionOnPostback="true"
    Title="The Title of your Page" 
    Language="C#" 
    MasterPageFile="~/Path/To/My/MasterPage.master" 
    AutoEventWireup="true" 
    CodeFile="MyPage.aspx.cs" 
    Inherits="MyPage" 
    %>

此外,如果您想访问母版页的派生类型,请使用@MasterType directive

<%@ MasterType VirtualPath="~/Path/To/My/MasterPage.master" %>

答案 1 :(得分:0)

可能是VS的错误,尝试使用您的母版页保存项目,然后关闭并重新打开VS.

如果不像上面提到的Uwe Keim那样手动添加母版页真的很容易。

相关问题