Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

What are the advantages of user controls over WebParts when dealing with SharePoint? Some I can think of are: familiarity, reusability, and development speed. I am planning to implement them in SharePoint publishing sites. Which ones should I go for?

share|improve this question
add comment

4 Answers

up vote 1 down vote accepted

The equivalent to a user control is a Visual Web Part, which is a web part based on a user control. This gives you all the advantages of the designer and markup editing, as opposed to a regular web part which follows the model of an ASP.NET custom control.

The advantage of building a web part, as opposed to just an ASP.NET control of either type, is that you are getting the ability to add and configure them at run-time through the SharePoint user interface. You also get a better editing experience in SharePoint Designer.

These advantages are considerable in relation to the modest additional development effort in my opinion. If you are doing SharePoint development I would recommend always building a control as a web part, even if you are only embedding it statically in a page layout or master page, It gives you more options for re-use while still allowing you to use it as if it was just an ASP.NET control.

share|improve this answer
add comment

It depends on what you want to achieve.

User Controls are controls which in general are ment to be statically placed on a specific pagelayout or masterpage. Like forinstance the QuickLaunch or GlobalNavigation are static controls in the masterpage, as they are ment to be shown on every single page, regardless of where you are on the site.

Webparts on the other hand are controls which are ment to be shown on specific chosen pages, but because of their flexibility also can be inserted as if they are user controls, requires them to be placed on masterpages or pagelayouts via SharePoint Designer.

So look at it this way:

  • Is your control supposed to be displayed on all pages?
    • Then make a user controls and place it in the masterpage.
  • Is your controls only supposed to be displayed on certain pages with a certain pagelayout?
    • Then make a user controls and place it in a pagelayout.
  • Is your control only supposed to be on one, maybe two specific pages
    • Then make a web part and insert it on the pages of your choice.

Hope this helps :)

share|improve this answer
add comment

All good answers, I'll just add that both WebPart and UserControl are derivatives of System.Web.UI.Control, and as such are just two different tools in the same box.

Normal practice is to build the UserControl, then add a WebPart that simply loads it. This gives you both options for use.

In your case you are probably going to use UserControl since publishing pages normally use a fixed Page Layout that end-users cannot edit or move around, so the additional advantages of a WebPart make no sense.

share|improve this answer
add comment

The are different things :-

  • UserControls are intended as a way to package a.. well.. control.. to make it easy for developers to re-use in other parts of a project

  • WebParts are intended as a way to package a piece of functionality for re-use in SharePoint by end users.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.