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!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!
0 comments:
Post a Comment