我是 asp.net(c#)的初学者。我正在尝试开发继承过程。在我的Web应用程序中,我创建了一个名为BaseClass.aspx
的页面。这应该是我要从中继承所有方法及属性的页面。我创建另一个名为DerivedClass.aspx
的页面。因此,我尝试从DerivedClass.aspx.cs
导出BaseClass.aspx.cs
并收到此错误:
无法加载类型BaseClass.aspx.cs
在DerivedClass.aspx
中:
<%@ Page Language="C#" AutoEventWireup="true" CodeFileBaseClass="BaseClass.aspx.cs" CodeFile="DerivedClass.aspx.cs" CodeBehind="DerivedClass.aspx.cs" Inherits="TestHerit.DerivedClass" %>
在BaseClass.aspx
中:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="BaseClass.aspx.cs" Inherits="TestHerit.BaseClass" %>
我尝试了网上阅读的所有解决方案,但没有解决问题。
请问有人可以帮我吗?
答案 0 :(得分:0)
是的
这是BaseClass.aspx.cs的内容:
namespace TestHerit
{
public partial class BaseClass : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
}
BaseClass.aspx的内容
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="BaseClass.aspx.cs"
Inherits="BaseClass" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Page sans titre</title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
DerivedClass.aspx.cs的内容
namespace TestHerit
{
public partial class DerivedClass : BaseClass
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
}
DerivedClass.aspx的内容
<%@ Page Language="C#" AutoEventWireup="true" CodeFileBaseClass="BaseClass.aspx.cs"
CodeFile="DerivedClass.aspx.cs" Inherits="DerivedClass" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Page sans titre</title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
我的Web应用程序从DerivedClass.aspx开始。
非常感谢。