【问题标题】:asp.net c# codefile not working properlyasp.net c#代码文件无法正常工作
【发布时间】:2015-05-27 20:06:16
【问题描述】:

我正在尝试将代码文件添加到我的 asp.net 母版页。我让它在单个页面上正常工作,但不能在我的母版页上这样做。

在我的 aspx 母版页中,我有:

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="Master.cs" Inherits="Master.Master" %>

然后我有一个文件名为:

Master.cs

下面的代码是:

namespace Master
{
    using System;

    public partial class Master : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Write("ALEX");
            Response.End();
        }
    }
}

据我所知,我的所有声明都是正确的,但我得到的错误是:

ASPNET: Make sure that the class defined in this code file matches the 'inherits' attribute, and that it extends the correct base class (e.g. Page or UserControl).

还有一行:

Line 5:      public partial class Master : System.Web.UI.Page

为红色。我之前遇到过这个错误,但我确定我的所有代码都是正确的,所以不知道为什么会出现这个错误?

也许主文件需要不同的设置,或者它在主页面上的工作方式不同?

【问题讨论】:

    标签: c# asp.net


    【解决方案1】:

    在类后面定义母版页代码时,要继承的基类是System.Web.UI.MasterPage,而不是System.Web.UI.Page

    【讨论】:

      猜你喜欢
      • 2011-11-06
      • 2017-02-28
      • 2017-08-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多