4

好的,我完全陷入了这个编译错误。这是一个网站(不是网络应用程序),.NET 2.0。

我在这个目录中有一个文件:welcome_teams

文件名:default.aspx

页面声明:

<%@ Page Language="C#" MasterPageFile="~/masters/Site.master" 
AutoEventWireup="true"    CodeFile="default.aspx.cs" 
Inherits="welcome_teams_default" %>`

代码背后

public partial class welcome_teams_default : System.Web.UI.Page

而且我不断收到此错误:确保此代码文件中定义的类与“继承”属性匹配

我尝试删除该文件,然后将其再次添加为“新项目”,无论如何,错误仍然存​​在。

有任何想法吗?

谢谢!

4

3 回答 3

3

因此,它与命名空间无关,它与 default2.aspx 页面有关,指向 default.aspx 页面。

The default2.aspx page's CodeFile attribute was set to "default.aspx.cs" which screwed it all up.

For anyone who might have this problem in the future though, you can sometimes solve it by changing CodeFile to CodeBehind.

Also, in theory it was a namespace issue, but god do I hate how Website projects handle namespaces.

于 2009-07-07T01:29:51.060 回答
1

很可能因为您的文件位于 Web 根目录内的文件夹中,当您创建它时,VS 会更改生成文件的命名空间。比如,如果您的站点名称是MyWebsite ,那么它的默认命名空间是 MyWebsite;

namespace MyWebsite

但是对于welcome_teams中的aspx文件,它应该是:

namespace MyWebsite.welcome_teams

所以在你的 aspx 页面中尝试改变:

<% Page ...  inherits="welcome_teams_default" %>

<% Page .. Inherits="MyWebsite.welcome_teams.welcome_teams_default" %>
于 2009-07-06T17:57:59.177 回答
0

您应该检查 default.designer.cs 文件,并确保它也具有相同的类名。有时,如果存在 Designer.cs 文件,并且手动编辑(但有时出于其他原因),则 .aspx 页面和后面的代码之间的同步可能会中断。要查看 .designer.cs 文件,您需要在项目中显示隐藏文件。

于 2009-07-06T17:29:24.583 回答