-2

I'm a beginner in asp.net (c#). I'm trying to develop an inheritance process. In my web application, I created a page called BaseClass.aspx. This is supposed to be the page from which I want to inherit all methods et properties. I create another page called DerivedClass.aspx. So I try to derive DerivedClass.aspx.cs from BaseClass.aspx.cs and I get this error:

Could not load the type BaseClass.aspx.cs

In DerivedClass.aspx:

<%@ Page Language="C#" AutoEventWireup="true" CodeFileBaseClass="BaseClass.aspx.cs" CodeFile="DerivedClass.aspx.cs"  CodeBehind="DerivedClass.aspx.cs" Inherits="TestHerit.DerivedClass" %>

In BaseClass.aspx:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="BaseClass.aspx.cs" Inherits="TestHerit.BaseClass" %>

I have tried all the solutions read on the net about this without solving the problem.

May anyone help me, please?

VijayD
  • 826
  • 1
  • 11
  • 33
  • 5
    Doesn't answer your question but; If your a beginner I would not bother learning asp.net (actually this is webforms), it has been superseded by MVC (you could argue this is also old fashioned now) learn that instead – Liam Jul 31 '18 at 12:55
  • Where is the code? – Thanos Markou Jul 31 '18 at 12:55
  • the nub of this is *So I try to derive DerivedClass.aspx.cs from BaseClass.aspx.cs* how do you do this? What do your classes look like? – Liam Jul 31 '18 at 12:57
  • Where did you create the file(s)? If you put it in App_Code you probably need to set the build action to Compile. – Crowcoder Jul 31 '18 at 12:59
  • Are you **100% sure** there is a file in your project **specifically called** `BaseClass.aspx.cs`? – mjwills Jul 31 '18 at 12:59
  • See https://stackoverflow.com/questions/10923971/asp-net-codefilebaseclass-attribute-vs-inherit-from-system-web-ui-page and also https://stackoverflow.com/questions/6213274/asp-net-parser-error-cannot-load-code-behind – Rui Jarimba Jul 31 '18 at 13:19

1 Answers1

0

Yes,

Here is the content of BaseClass.aspx.cs:

namespace TestHerit
{
  public partial class BaseClass : System.Web.UI.Page
  {
    protected void Page_Load(object sender, EventArgs e)
    {

    }
  }
}

The content of 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>

The content of DerivedClass.aspx.cs

 namespace TestHerit
 {
     public partial class DerivedClass : BaseClass
     {
         protected void Page_Load(object sender, EventArgs e)
         {

         }
     }
 }

The content of 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>

My web application starts with DerivedClass.aspx.

Thanks a lot.