One simple fact is that you can't use the visual designer when creating
WebParts, because webparts can't inherit directly from the .NET classes. So
you have to create and configure all controls in the webpart through code,
and output the controls and graphic through either the CreateChildControls
method or the Render method (though the first is the easiest to use).
So your trouble might be that you created your control using the designer
and then try to let the class inherit from
System.Web.UI.WebControls.WebParts.WebPart which then won't work.
One fix is to rewrite the whole webpart in code.
This article also might be of help (though it is written for SharePoint
WebParts):
http://www.devx.com/dotnet/Article/26732
"Jav" wrote:
The reason I am asking is because the docs suggest that is a "better" way of
doing things. Unfortunately their examples do not explain much.
Jav
"tdavisjr" wrote:
So what are you asking? If you know a usercontrols is going to get
wrapped in a GenericWebPart why are you trying to inherit from
WebParts.WebPart
If you want to inherit from this class, then you may have to write a
custom control.
I don't know if implementing the IWebPart interface would give you the
same errors; but you can try it an see.
Jav wrote:
I create a UserControl (.ascx), and then change it in code to:
Inherits System.Web.UI.WebControls.WebParts.WebPart
expecting that it will now be treated as a WebPart. But this immediately
generates 2 errors. How does one go about creating a WebPart by inheriting
as above?
>
(I know that I can drag a UserControl into a WebPartZone and it will be
wrapped in a GenericWebPart.) Thanks
>
Jav