467,903 Members | 1,895 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,903 developers. It's quick & easy.

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

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!
Nov 18 '05 #1
  • viewed: 2401
Share:
1 Reply
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

On Fri, 20 Feb 2004 06:06:05 -0800, "Chuck Haeberle"
<an*******@discussions.microsoft.com> wrote:
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!


Nov 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by Brent | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.