Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > simple asp.net/C# inheritance problem

Reply
Thread Tools

simple asp.net/C# inheritance problem

 
 
Ranginald
Guest
Posts: n/a
 
      05-05-2006
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!

 
Reply With Quote
 
 
 
 
David Hogue
Guest
Posts: n/a
 
      05-15-2006
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.

--
David

Ranginald wrote:
> 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!
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
C++ Struct inheritance against class inheritance johnsonlau C++ 1 07-21-2008 04:58 PM
Interface inheritance vs Implementation inheritance. Daniel Pitts Java 27 02-27-2008 01:37 AM
Private Inheritance and Publice Inheritance karthikbalaguru C++ 9 09-10-2007 01:05 PM
mul. inheritance & overloading operator new/delete solved by virtual base inheritance? cppsks C++ 0 10-27-2004 07:49 PM
Private access modifier and Inheritance (Inheritance implementation in Java) maxw_cc Java 1 12-21-2003 11:38 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57