我正在尝试使母版页与内容页配合使用,从而允许内容页访问母版页控件。我收到错误:
Parser Error Message: The 'mastertype' directive must have exactly one attribute: TypeName or VirtualPath
这是对的:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="viewProduct.aspx.cs" Inherits="AlphaPackSite.viewProduct"
MasterPageFile="MasterPages/Main.master"
title="Hi there!"
%>
<%@ MasterType TypeName="Main" VirtualPath="MasterPages/Main.master" %>
我的母版页是:
namespace AlphaPackSite
{
public partial class Main : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
我对命名空间有点困惑,因此可能弄错了,但我相信现在所有页面都在同一个命名空间中。
更新
当我把它转到:
<%@ MasterType VirtualPath="MasterPages/Main.master" %>
我不断收到错误:
Compiler Error Message: CS0030: Cannot convert type 'AlphaPackSite.Main' to 'ASP.masterpages_main_master'
Source Error:
Line 147: public new ASP.masterpages_main_master Master {
Line 148: get {
Line 149: return ((ASP.masterpages_main_master)(base.Master));
Line 150: }
Line 151: }
最佳答案
除非您想在当前页面(其中编写了此代码)中保留母版页的引用,否则我建议您删除 <%@ MasterType VirtualPath="MasterPages/Main.master" %>
线。
此行提供了一种访问页面母版页的方法(例如,当您必须更改母版页上的标签或菜单需要添加更多项目等时)。 如果母版页的内容不需要对内容页进行任何更改/更新,则无需使用 MasterType 标记。因为同时使用 MasterPageFile="MasterPages/Main.master
和MasterType
,你会让编译器感到困惑(即使母版页是相同的)。
更新
如果必须保留 MasterType 标记,请删除 MasterPageFile="MasterPages/Main.master
页面指令中的属性。
关于c# - ASP.net c# 母版页问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3700116/