The Proper Web Part Control Class for a SharePoint 2010 Sandbox Solution

This post is one post in a series of posts I penned in hopes it would help those looking to move a SharePoint 2010 Visual Studio 2010 farm based solution to a sandbox. There are many gotcha’s and pitfalls that you may run into or you may want to be aware of. You can learn more about this series here as well as download the CodePlex Project, From the Farm to the Sandbox, which includes the sample farm and sandbox solutions references through this series.
The related posts include:
Automatically Check In Files in a SharePoint 2010 Sandbox Feature Event Receiver
SharePoint 2010 Sandbox Feature Deactivation – Removing Module Assets
Custom Properties in a SharePoint 2010 Sandbox Web Part
Why CSSRegistration Will Not Work in a SharePoint 2010 Sandbox Solution
Link to JavaScript Files in a SharePoint 2010 Sandbox Solution

Different Types of Webparts

When you create a web part in a SharePoint project that was original built as for a farm solution, Visual Studio will assume that your web part will inherit from Microsoft.SharePoint.WebPartPages.WebPart. This is great because then you have access to more specific SharePoint web part properties and functions such as overriding the web part’s GetToolParts() function (public override ToolPart[] GetToolParts()) so that you can build your own ToolParts (Microsoft.SharePoint.WebPartPages.ToolPart).
SharePoint sandbox solutions do not have access to Microsoft.SharePoint.WebPartPages.WebPart nor Microsoft.SharePoint.WebPartPages.ToolPart, so you instead need to make sure that your web part inherits from System.Web.UI.WebControls.WebParts.WebPart. In fact it is now considered best practices to always have your web parts inherit from System.Web.UI.WebControls.WebParts.WebPart so that you can move it to SharePoint online, or to other environments.
So the key is, a web part for a SharePoint Sandbox must inherit from System.Web.UI.WebControls.WebParts.WebPart. In general this should not be a problem. I will describe how to replace a custom ToolPart control in the next post.

Visual Web Parts and Sandboxes

There is no OOTB Visual Web Part that is compatible with a sandbox because part of the visual aspects are required to be installed to the server hive. But not to worry, there are some great work-arounds. I suggest the following article from MSDN.
For a complete review of the Farm and Sandbox solutions’ Feature Event Receiver, please reference From the Farm to the Sandbox for the full code. Also, please do not forget to check out the other posts in this series, all related to converting a farm solution to a sandbox solution.

Leave a Comment

Your email address will not be published. Required fields are marked *

Enter Code *

Filed Under


Do you need to build a custom search-driven component for your #digitalworkspace while saving thousands of hours of development time?

Join us on as we lift the hood of #PnP Modern Search v4, show you how it's built, & take you on a live coding adventure.

#Hybridwork is more than just a buzzword to latch onto; it’s the future for many organizations for the unforeseeable future. So, how can you use #Microsoft365 for #hybridwork? Let's breaks it down…

It's that time again! Join the #PixelMillWebinars on 4/29 where @EricOverfield lifts the hood of #PnP Modern Search v4, shows how it's built, & takes you on a live coding adventure to customizing your own web part using the power of the existing codebase.

What? Anchor links now work in #SharePoint site navigation! This fix snuck in and I completely missed it. Use them to create a TOC for long pages or cross link between pages. They work in text or quick links web parts & nav too!

A big thank you to David Leveille and @CrushNetworks for having our President + Co-Founder @EricOverfield on this episode of #TheVirtualWaterCooler!

Subscribe to PixelMill's

* indicates required

Let's Talk Digital
Workspaces Today

Get In Touch