ASP.Net 2.0 Inheritance Changes from ASP.Net 1.x

February 6, 2006

ASP.Net 2.0 is a great advance in many ways, particularly the partial classes which will help cut down on the amount of time required to build a new form since you won’t have to declare everything on the back page.  There is one area that has become somewhat of a hot topic for those building more advanced web applications.  What is at issue appears to be the new inheritance model of ASP.Net, which was changed in order to make ASP.Net easier to use for less experienced developers.  The inheritance model in ASP.Net 2.0 does not allow classes (code behind) from user controls or web forms to be shared inside the application.   Additionally all code that is not directly tied to a form or user control is by design supposed to reside in a new fixed folder called “App_Code”. 

 For an example, imagine that you created a base class for all of your pages to inherit from, you would need to place that class in the “App_Code” folder.  Once you place that base class in the “App_Code” folder you cannot access any of the forms or user controls outside the “App_Code” folder.  So let’s say you have a user control called “HeaderTemplate” and you had a base class that your pages inherited from called “DefaultTemplate.”  The “DefaultTemplate” resides in the “App_Code” folder and the “HeaderTemplate” resides in the main ASP.Net structure.  The “DefaultTemplate” cannot access or declare the “HeaderTemplate” control because the “App_Code” folder is essentially treated like a separate class library.  The ASP.Net application can see the “App_Code” folder, like it was a depedency, but the “App_Code” folder cannot see the ASP.Net application. 

In ASP.Net 1.x the application structure was much less rigid and more flexible and allowed for greater control over how classes inherited from one another and the interoperability of these classes was powerful.  There are several articles that I have found pertaining to this discussion here is one that really explains in great detail the information above Understanding Page Inheritance in 2.0 by Rick Strahl.

Interestingly, I have also come across another article which shows that a solution from Microsoft may be on the way.  Apparently so many of us have complained about the change that Microsoft is introducing a new project type tenantatively called “Web Project” which will give the benefiits of the partial classes with a more flexible ASP.Net 1.x approach.  I am hopeful that the new model will solve the inheritance problem that I describe above.  For updates on the “Web Project” model view Scott Guthrie’s article: New Web Project Model Option Coming for VS 2005



One Response to “ASP.Net 2.0 Inheritance Changes from ASP.Net 1.x”

  1. Vijay Says:

    Thank you!! Great post…Your article made my day

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: