Classed derived from abstract class will not load in designer?

R

RND

I have this class:

Public MustInherit Class ucBasicListingUserControl
Inherits System.Web.UI.UserControl
Public Event OnDone()
Public MustOverride Sub LoadData(Optional ByVal pstrSignalParam As
String = "")
Public MustOverride WriteOnly Property objListings() As Listings
Public Sub RaiseOnDoneEvent()
Try
RaiseEvent OnDone()
Catch ex As Exception
LogException(ex)
End Try
End Sub
End Class

For several usercontrols, I inherit from the above class instead of
UserControl in the code behind file. When I do that, none of the controls
will load in designer mode in the IDE. If I change to inherit from
UserControl, they load fine. I saw a news group message that implied this
is fixable by doing something in the base class, but I have not been able to
fix it. The above seeems so basic, I am wondering why the derived class can
not load.
 
R

RND

I forgot to include the error message in VS2003 which is:

"The file could not be loaded into the Web Forms designer. Please correct
the following error and then try loading ti again: Type Abstract Make sure
all of the classes used in the page are built or reference in the project.
Click Help for more information."
 
G

Guest

Hi RND,

Thank you for posting in the community!

Based on my understanding, you inherit from the UserControl, but it does
not work well for you.

==============================
Where do you place your abstract ucBasicListingUserControl's definition?

Do you nest your ucBasicListingUserControl's definition in your
usercontrol's definition(see below #1), or in the same hierarchy as your
usercontrol's definition(see below #2)?

#1.
Public Class MyUserControl
Inherits ucBasicListingUserControl

.................

'ucBasicListingUserControl's definition
Public MustInherit Class ucBasicListingUserControl
Inherits System.Web.UI.UserControl
...........
End Class
End Class

#2.
Public Class MyUserControl
Inherits ucBasicListingUserControl

..................

End Class

'ucBasicListingUserControl's definition
Public MustInherit Class ucBasicListingUserControl
Inherits System.Web.UI.UserControl
...........
End Class

If you use #1 way, your project will not work well. Because MyUserControl
inherits from ucBasicListingUserControl, which is defined in
MyUserControl(In this situation, MyUserControl can not see
ucBasicListingUserControl).
Actually, if you do in #1 way in C#, a compile error will generate. "The
type or namespace name 'abstractclass' could not be found (are you missing
a using directive or an assembly reference?)"

Anyway, you problem may not be above. For your specific error message: "The
file could not be loaded into the Web Forms designer", there may be a lot
of possibility. The most common reason is "Inherits" in the UserControl
Page directive. You should make sure it have the correct value.

For more information and possible reason, please refer to:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbref/html/
vberrthefilecouldnotbeloadedintowebformsdesigner.asp

============================
Please apply my suggestion above and let me know if it helps resolve your
problem.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
R

RND

Thanks for the reply.

The abstract class is in its own clas file (xxx.vb) in the same namespace so
it is like your #2 description. BTW. The application works fine this way, it
just does not allow editing of the ASCX in the design window. The inherits
directive in the pages all point at the derived class and not at the
abstract class.
 
G

Guest

Hi RND,

Thanks very much for your feedback.

Oh, I have reproduced out your problem. After doing some further research,
I found that this is a know issue for VS.net designer.

We do not support visual inheritence in the web form designer. If you do
this, then "Type Abstract" error will generate. To workaround this issue,
you must make your base class as a non-abstract class.(Remove
"MustInherit", and replace "MustOverride" with "Overridable")

Also, there is also a MasterPages demo available on
http://www.asp.net/ControlGallery/ControlDetail.aspx?Control=385 created by
the ASP.Net team that shows another approach.

The below article may also help you:
"Implementing Page Controller in ASP.NET"
http://msdn.microsoft.com/architecture/patterns/default.aspx?pull=/library/e
n-us/dnpatterns/html/ImpPageController.asp

In this article, the author shows a note for this issue:
"Note: It would be better to define the BasePage class as abstract, because
doing so would force the implementers to provide an implementation for
PageLoadEvent. However, in Microsoft Visual Studio .NET, it is not possible
to define this base class as abstract."

Hope it can help you.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
G

Guest

Hi RND,

Does my reply make sense to you? Is your problem resolved?

Please feel free to feedback, I will help you. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

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

Top