473,385 Members | 1,606 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to create a WebPart?

Jav
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
Jun 12 '06 #1
3 1714
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


Jun 12 '06 #2
Jav
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


Jun 14 '06 #3
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
Aug 1 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: J. Jespersen | last post by:
Hi people, I fiddling with webparts, and have created my own custom webpart from scratch. The webpart itself is contained in a myPart.dll I have two different sites. SiteA and SiteB. Both are...
3
by: DexHex | last post by:
Hi, I am stumpt. Is there anyway to set the background image on a webpart title?
1
by: milmus tender | last post by:
Hi, is it possible to generate dynamicly new WebPart Pages? Each user of my application should have the possibility to save many different Views (WebPart Pages). Thanks, Milmus
0
by: arthernan | last post by:
I have an almost finished page that uses webparts. And this is the expected functionality. A logged on user hits a button and the button opens a WebPart. Then te user logs off, next time he logs on...
2
by: arthernan | last post by:
I have an almost finished page that uses webparts. And this is the expected functionality. A logged on user hits a button and the button opens a WebPart. Then the user logs off, next time he logs...
2
by: MrCrool | last post by:
Hi I am trying to develop WebParts that will interact with each other to make up a highly customizable "system", but I am having trouble with the order in which the webparts connect and...
0
by: =?Utf-8?B?QWtzaGF5?= | last post by:
I'm adding UserControls as WebPart at runtime to a WebPartZone. This is working fine but when I add two or more UserControl instances, the UserControls are overlapping each other i.e. When I add...
0
by: Manpreet | last post by:
Hi, I have a web part page with a toolbar webpart and a grid webpart. In the toolbar, I have menu-items to update a field. For selecting the value of the field I have another asp.net webform...
4
by: Arnab das | last post by:
I am working in asp.net webpart.I want to show the delete warning message in a modal popup. How can I achieve this?
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.