simple asp.net/C# inheritance problem

Discussion in 'ASP .Net' started by Ranginald, May 5, 2006.

  1. Ranginald

    Ranginald Guest

    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!
    Ranginald, May 5, 2006
    #1
    1. Advertising

  2. Ranginald

    David Hogue Guest

    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!
    >
    David Hogue, May 15, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. maxw_cc
    Replies:
    1
    Views:
    3,114
    Martijn van Steenbergen
    Dec 21, 2003
  2. cppsks
    Replies:
    0
    Views:
    801
    cppsks
    Oct 27, 2004
  3. karthikbalaguru
    Replies:
    9
    Views:
    1,023
  4. Daniel Pitts
    Replies:
    27
    Views:
    1,872
    Mike Schilling
    Feb 27, 2008
  5. johnsonlau
    Replies:
    1
    Views:
    759
    Kai-Uwe Bux
    Jul 21, 2008
Loading...

Share This Page