Subclassing from System.Web.UI.Page - Designer Error

G

Guest

We have need to share functionality across all of our application web pages, so we decided to subclass from System.Web.UI.Page. When we create a new aspx, the Visual Studio designer automatically puts in the codebehind, as such:

public class testsubclass : System.Web.UI.Page

We change this to be:

public class testsubclass : OurProject.Library.BaseWebPage

Which is defined as:

public class OurProject.Library.BaseWebPage : System.Web.UI.Page

The application will compile and run and all inheritance operates as expected. However, the designer stops working with the aspx file.

If you have the aspx file closed and open it, you get only an editor for the raw HTML, the designer will not open and the error:

An exception occurred while trying to create an instance of OurProject.Library.BaseWebPage. The exception was "Object reference not set to an instance of an object."

It also says: make sure all of the classes used in the page are built or referenced in the project.

I've tried opening it with the Library project which contains BaseWebPage included in the solution, and I've tried it with the Library project being compiled and the resulting DLL referenced. (Debug compile only...)

If you revert the testpage back to System.Web.UI.Page and close and reopen the aspx file, the designer works properly. If you have the designer open and then change it back to the subclass type derived from Page, the error occurs and while the designer stays open, the toolbox controls stop working and the designer is rendered useless.

Any advice would be most apprciated!
 
M

Mike Bridge

Have you tried this with VS.net 2003? I had problems inheriting a
code-behind from a superclass in VS.net 2002, but they all disappeared
when I upgraded.

-Mike
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top