MOSS Forum

Ask Question   UnAnswered
Home » Forum » MOSS       RSS Feeds

Webpart Development Question

  Asked By: Nelson    Date: Nov 30    Category: MOSS    Views: 932

Quick question about webpart development in MOSS. My
current method to develop webparts in Visual Studio is
by creating an assembly project and adding the
SharePoint references. I build a class that inherits
from WebPart that spits out strings of html. Pretty

I'd prefer a development method that separates the
html from the code-behind, like an asp.net user
control. Anyone have any suggestions?



6 Answers Found

Answer #1    Answered By: Jagdish Joshi     Answered On: Nov 30

Webparts inherit from server controls. You normally build  a webpart  by
overriding two methods CreateChildControls and RenderContents.
CreateChildControls is used to instantiate controls like buttons,
textboxes, etc and RenderContents renders them into HTML. You can also
embed usercontrols inside a webpart wrapper, but there are some good
reasons not to do that. If you use constituent controls wisely the only
HTML that you will need to write manually should be things like <DIV>
tags for spacing and formatting.

Answer #2    Answered By: Shara Johnson     Answered On: Nov 30

Could you please elaborate on the some of good reasons of not using
usercontrols for webpart  development?

Answer #3    Answered By: Victoria Bell     Answered On: Nov 30

The primary one is that the UserControl is deployed to the SharePoint
environment as source code, not compiled MSIL. The site has to Compile
the code to MSIL before it can compile it to assembly. This causes a
performance issue that can slow down the rendering of the control.

Second, since the control is rendered as a control inside another
control it makes it more difficult to surface the properties of the user
controls constituent controls for use in the webpart.

Third, it makes it more difficult to take advantage of the features of
the webpart  object model like easy personalization of properties, easy
connections between webparts, data catching, etc.

Answer #4    Answered By: Cassidy Sharpe     Answered On: Nov 30

I personally recommend using .ascx controls embedded in your custom web
parts. This allows you to use the VS 2005 GUI design to design the
contents of your web parts. You can also easily wrap the .ascx control in
a .aspx page to unit test the control. As a side benefit, you can
incorporate a single .ascx control into multiple web parts (each web part
will either set a different property value or call a different method).

Answer #5    Answered By: Linda Mason     Answered On: Nov 30

Definitely the
information provided will help me make better decisions.

Also have you guys used SmartPart? It looks like it is a good utility
for webpart  development with user controls.

Answer #6    Answered By: Hans Weiss     Answered On: Nov 30

Since I don't normally do .ascx controls inside webParts I don't use
SmartPart. When I do demonstrate their use I just wrap them in a custom
webpart myself. Smartpart is pre-written to do that, but in order to
maintain all the different things you would like to do with an .ascx
control it makes a number of assumptions that add extra code that isn't
normally needed. So I stick to doing it myself that way I have the

Didn't find what you were looking for? Find more on Webpart Development Question Or get search suggestion and latest updates.