A colleague of mine recently asked me if the WebPart he was writing should inherit from the ASP.Net WebPart class or the SharePoint WebPart class. He was a bit confused because he had seen a few articles online that talked about the benefits of inheriting from one class or the other.

Some articles recommend using ASP.Net WebPart class for general ASP.Net interoperability while other articles recommend using the SharePoint WebPart class to gain access to its additional features. This MSDN article enumerates the list of features provided exclusively by the Windows SharePoint Services WebPart class:

  • Cross page connections

  • Connections between Web Parts that are outside of a Web Part zone

  • Client-side connections (Web Part Page Services Component)

  • A data caching infrastructure that allows caching to the content database

My colleague was confused. He wanted the ASP.Net interoperability but he wasn’t sure if he would regret not having access to the additional SharePoint WebPart class’ feature.

To my mind, the decision is very simple for most SharePoint developers: use the the SharePoint WebPart class. While the idea of general ASP.Net interoperability is nice, it is not likely to pan out. The reason: if you are writing a web part for SharePoint, you will likely want access to the SharePoint object model to work with list and document data, get SharePoint context, etc…. As soon as you add a reference to the Microsoft.SharePoint.dll assembly to your project and use any of its types, your assembly has already been strongly tied to SharePoint and will not work on a plain ASP.Net web site. If your assembly is already tied to SharePoint, then you may as well get the added functionality of the SharePoint WebPart by inheriting from it.

Technorati Tags: WSS,SharePoint,MOSS,ASP.Net