simple asp.net/C# inheritance problem

R

Ranginald

I am learning OOP and C# and am using VWDExpress to create some
practice examples to understand inheritance. Could someone explain why
the following is happening:

I get the error: 'The type or namespace _Default does not exist in the
namespace "Lefantze"'

Here is the code:

default.aspx.cs | in the default.aspx page
inherits="Lefantze._Default"
===========.
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace Lefantze
{
public partial class _Default : System.Web.UI.Page
{
public void Page_Load(object sender, EventArgs e)
{
Label1.Text = "Lefantze test: _Default class";
}
}

Now I try to inherit from _Default in the second class, Default2
default2.aspx.cs | in the default2.aspx.cs page the
inherits="Lefantze.Default2"
======
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace Lefantze
{
public partial class Default2: Lefantze._Default
{
protected void Page_Load(object sender, EventArgs e)
{

}
}

}

Thanks!
 
D

David Hogue

Hi Ranginald,

In vs2003/.net 1.1 this would have worked, but with how web projects
were changed in .net 2.0 it won't work. The classes (_Default and
Default2) are compiled to two separate assemblies and can't reference
each other.

I would make an App_Code folder and create a new base class there, then
you can inherit from that class in your pages. Classes in the App_Code
folder are compiled to the same assembly and can be used from the page
classes. I haven't used VWDExpress yet, but I think this should work.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top