【问题标题】:Getting an error in my asp.net page在我的 asp.net 页面中出现错误
【发布时间】:2010-01-17 11:25:45
【问题描述】:

我收到以下错误消息。

有什么办法解决这个问题吗?

编译错误 说明:在编译服务此请求所需的资源期间发生错误。请查看以下特定错误详细信息并适当修改您的源代码。

编译器错误消息:ASPNET:确保此代码文件中定义的类与“继承”属性匹配,并且它扩展了正确的基类(例如 Page 或 UserControl)。

来源错误:

Line 1:  using System;
Line 2:  using System.Data;
Line 3:  using System.Data.SqlClient;

【问题讨论】:

  • 向我们展示一些代码怎么样。特别是,在代码隐藏中显示类声明,并向我们显示 .aspx 文件中的 Page 指令。
  • 我正在尝试粘贴代码,但代码长度超过 600 个字符;所以我会尝试将它粘贴成两块。这是我写的唯一代码: using System;使用 System.Data;使用 System.Data.SqlClient; class SqlConnectionDemo { static void Main() { SqlConnection conn = SqlConnection("Data Source=(local); Initial Catalog=JobSearchManager;Integrated Security = SSPI"); SqlDataReader rdr = null;试试 { conn.Open(); SqlCommand cmd = new SqlCommand("select * from Agency", conn);
  • rdr = cmd.ExecuteReader; while (rdr.Read()) { Console.WriteLine(rdr[0]); } } 最后 { if (rdr != null) { rdr.Close(); } if (conn != null) { conn.Close; } } } }
  • aspx 页面是: ttp://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" rel="nofollow" target="_blank">w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> w3.org/1999/xhtml"> 无标题页面

标签: asp.net


【解决方案1】:

这正是错误所说的:

您的 .ASPx 文件页面标题有 2 个与您的问题相关的属性:CodeFile 和 Inherits。 CodeFile 属性中引用的文件必须具有与 Inherits 属性中定义的同名的类,并且该类必须是 Page 或 UserControl。

如果这不能解决您的问题。告诉我。

【讨论】:

  • 安德烈已经给你正确答案了,你需要花时间去理解@Page指令中的“CodeFile”和“Inherits”是什么意思。
  • 另外,确保没有其他页面(意外)尝试从相同的代码隐藏文件中继承类。
猜你喜欢
  • 1970-01-01
  • 2012-05-11
  • 2012-06-17
  • 1970-01-01
  • 2010-10-17
  • 1970-01-01
  • 1970-01-01
  • 2023-04-07
  • 2016-01-18
相关资源
最近更新 更多