Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx thread: Question about Inheritance...


Message #1 by "George Walley" <booyah@m...> on Thu, 10 Jan 2002 17:53:42
Does anyone know why you seem to need to specify the web application name 

in a @Page directive when using inheritance?



For example, I have to type:

(where "WebEntryTest" is my web application name)



<%@ Page Language="vb" AutoEventWireup="true" Codebehind="Master.aspx.vb" 

Inherits="WebEntryTest.Common"%>



instead of just:



<%@ Page Language="vb" AutoEventWireup="true" Codebehind="Master.aspx.vb" 

Inherits="Common"%>



...to inherit the class "Common" in the master.asp.vb file



It seems to be redundant becaues the webform and master.aspx.vb file are 

both in the same web application space together.  Is this really needed or 

am I doing something wrong?



Thanks,

george
Message #2 by "Albert Davis" <albertdavis@h...> on Thu, 10 Jan 2002 12:56:23 -0500
WebEntryTest in this case is usually referring to the Namespace used..





>From: "George Walley" <booyah@m...>

>Reply-To: "ASP+" <aspx@p...>

>To: "ASP+" <aspx@p...>

>Subject: [aspx] Question about Inheritance...

>Date: Thu, 10 Jan 2002 17:53:42

>

>Does anyone know why you seem to need to specify the web application name

>in a @Page directive when using inheritance?

>

>For example, I have to type:

>(where "WebEntryTest" is my web application name)

>

><%@ Page Language="vb" AutoEventWireup="true" Codebehind="Master.aspx.vb"

>Inherits="WebEntryTest.Common"%>

>

>instead of just:

>

><%@ Page Language="vb" AutoEventWireup="true" Codebehind="Master.aspx.vb"

>Inherits="Common"%>

>

>...to inherit the class "Common" in the master.asp.vb file

>

>It seems to be redundant becaues the webform and master.aspx.vb file are

>both in the same web application space together.  Is this really needed or

>am I doing something wrong?

>

>Thanks,

>george












_________________________________________________________________

Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp.



Message #3 by "Albert Davis" <albertdavis@h...> on Thu, 10 Jan 2002 13:33:10 -0500
Sorry I should have been more specific - this behavior that you are 

observing is just a VB.net only behavior where you cannot see the namespace 

within your codebehind page....  In any web project you always have a "Root" 

or "Default" Namespace found in the properties dialog when you right click 

on your project and choose properties...  If you just want "Common" in the 

directive then what you are saying is that this class is found at the root 

level (not advisable), so just remove the entry made within the "Root 

Namespace" input box and then go and change your directive to read "Common" 

instead of "WebEntryTest.Common"...



Al





>From: "Albert Davis" <albertdavis@h...>

>Reply-To: "ASP+" <aspx@p...>

>To: "ASP+" <aspx@p...>

>Subject: [aspx] Re: Question about Inheritance...

>Date: Thu, 10 Jan 2002 12:56:23 -0500

>

>WebEntryTest in this case is usually referring to the Namespace used..

>

>

>>From: "George Walley" <booyah@m...>

>>Reply-To: "ASP+" <aspx@p...>

>>To: "ASP+" <aspx@p...>

>>Subject: [aspx] Question about Inheritance...

>>Date: Thu, 10 Jan 2002 17:53:42

>>

>>Does anyone know why you seem to need to specify the web application name

>>in a @Page directive when using inheritance?

>>

>>For example, I have to type:

>>(where "WebEntryTest" is my web application name)

>>

>><%@ Page Language="vb" AutoEventWireup="true" Codebehind="Master.aspx.vb"

>>Inherits="WebEntryTest.Common"%>

>>

>>instead of just:

>>

>><%@ Page Language="vb" AutoEventWireup="true" Codebehind="Master.aspx.vb"

>>Inherits="Common"%>

>>

>>...to inherit the class "Common" in the master.asp.vb file

>>

>>It seems to be redundant becaues the webform and master.aspx.vb file are

>>both in the same web application space together.  Is this really needed or

>>am I doing something wrong?

>>

>>Thanks,

>>george




>

>

>

>

>_________________________________________________________________

>Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp.

>

>












_________________________________________________________________

Join the world?s largest e-mail service with MSN Hotmail. 

http://www.hotmail.com



Message #4 by "John Wormald" <johnswormald@h...> on Fri, 11 Jan 2002 14:19:01
George beat me to this question. Albert, are suggesting that you should 

always specify a default namespace for your application? My application 

does and consequently VS always puts the namespace in the Inherits 

attribute of the Page directive every time I amend the code behind file. 

However, I always get an error at run time saying that the base type does 

not exist in the source file. I then have to remove the namespace from the 

Inherits directive for the page to load without an error. Am I missing 

something here?



John









> Sorry I should have been more specific - this behavior that you are 

> observing is just a VB.net only behavior where you cannot see the 

namespace 

> within your codebehind page....  In any web project you always have 

a "Root" 

> or "Default" Namespace found in the properties dialog when you right 

click 

> on your project and choose properties...  If you just want "Common" in 

the 

> directive then what you are saying is that this class is found at the 

root 

> level (not advisable), so just remove the entry made within the "Root 

> Namespace" input box and then go and change your directive to 

read "Common" 

> instead of "WebEntryTest.Common"...

> 

> Al

> 

> 

> >From: "Albert Davis" <albertdavis@h...>

> >Reply-To: "ASP+" <aspx@p...>

> >To: "ASP+" <aspx@p...>

> >Subject: [aspx] Re: Question about Inheritance...

> >Date: Thu, 10 Jan 2002 12:56:23 -0500

> >

Message #5 by Msingh9@a... on Fri, 11 Jan 2002 12:37:37 EST
Please Note my Future email address for communication:



jhand_mohan@y...



Kind Regards:

Mohan Jhand

Message #6 by "Albert Davis" <albertdavis@h...> on Fri, 11 Jan 2002 14:24:55 -0500

For a VB ASP.NET application anytime you create a new webform the IDE will 

place an entry within the "Root Namespace" attribute within the properties 

dialog for that project - likewise within your aspx the IDE will add the 

inherits attribute which will include this "Root Namespace" and the class 

name within your codebehind - so you will get 

"Inherits=RootNamespace.CodeBehindClassName" - if you add a wrapping 

namespace within your codebehind class you must adjust the Inherits 

attribute to be 

"Inherits=RootNamespace.YourNewNamespace.CodeBehindClassName".  To delete 

this "Root Namespace" you must go to the properties dialog of the project 

and remove the entry for "Root Namespace".  When you do this you will need 

to then adjust your aspx Inherits attribute to 

"Inherits=CodeBehindClassName".  If you now add a namespace within your 

codebehind page you will need to adjust your Inherits attribute once more to 

"Inherits=YourNewNamespace.CodeBehindClassName"...  This behavior within the 

IDE is a very good one to protect you from having class conflicts but I do 

think there should be a checkbox option within the IDE that read's "Add's 

Root Namespace on your behalf..."  or something of that sort.  I also think 

that the IDE not showing you the "Root Namespace" that it added is really 

confusing to anyone new to the IDE (just my thoughts)...



For a C# ASP.NET application the procedure is identical minus 2 exceptions:



1)  The projects properties namespace attribute is called "Default 

Namespace" but behaves the same as VB's "Root Namespace".



2)  The IDE always places the "Default Namespace" that is created for you 

within the CodeBehind page so it is more apparent to the developer, so when 

you look at your aspx page for the first time you will see that the Inherits 

attribute "Inherits=DefaultNamespace.CodeBehindClass" always coincides with 

the codebehind reading:

Namespace DefaultNamespace{

Public Class CodeBehindClass : System.Web.UI.Page{

  Public CodeBehindClass(){

  }

}

}



My advice is to always have your class within the Namespace that your 

project creates for you or you go through the steps to create your own 

(described above if using VB) whether or not you are using C# or VB.  Your 

more protected from class conflicts as well as it follows the fundamental 

approach to .NET Class development.  The error that you are seeing once a 

request is made is referring to the fact that your aspx page is trying to 

find a Namespace and having no such luck - follow what I explained above and 

the runtime shouldn't have any further "code confusion" or understanding 

with what is needed, also remember that the complier will not catch these 

conflicts during a build...



Al



>From: "John Wormald" <johnswormald@h...>

>Reply-To: "ASP+" <aspx@p...>

>To: "ASP+" <aspx@p...>

>Subject: [aspx] Re: Question about Inheritance...

>Date: Fri, 11 Jan 2002 14:19:01

>

>George beat me to this question. Albert, are suggesting that you should

>always specify a default namespace for your application? My application

>does and consequently VS always puts the namespace in the Inherits

>attribute of the Page directive every time I amend the code behind file.

>However, I always get an error at run time saying that the base type does

>not exist in the source file. I then have to remove the namespace from the

>Inherits directive for the page to load without an error. Am I missing

>something here?

>

>John

>

>

>

>

> > Sorry I should have been more specific - this behavior that you are

> > observing is just a VB.net only behavior where you cannot see the

>namespace

> > within your codebehind page....  In any web project you always have

>a "Root"

> > or "Default" Namespace found in the properties dialog when you right

>click

> > on your project and choose properties...  If you just want "Common" in

>the

> > directive then what you are saying is that this class is found at the

>root

> > level (not advisable), so just remove the entry made within the "Root

> > Namespace" input box and then go and change your directive to

>read "Common"

> > instead of "WebEntryTest.Common"...

> >

> > Al

> >

> >

> > >From: "Albert Davis" <albertdavis@h...>

> > >Reply-To: "ASP+" <aspx@p...>

> > >To: "ASP+" <aspx@p...>

> > >Subject: [aspx] Re: Question about Inheritance...

> > >Date: Thu, 10 Jan 2002 12:56:23 -0500

> > >

>












_________________________________________________________________

Send and receive Hotmail on your mobile device: http://mobile.msn.com




  Return to Index