11.2. Creating Custom Web Parts

Like the previous version of SharePoint and ASP.NET 2.0, developers are not limited to the Web Parts provided "out of the box" (OOTB). Developers are free to create custom Web Parts — for use within Publishing sites or any SharePoint site, for that matter.

Web Parts are ASP.NET 2.0 server controls, so creating Web Parts involves working in a pure code model, rather than defining the presentation experience declaratively as is done with markup in *.ASPX and *.ASCX files. This is often frustrating to ASP.NET 2.0 developers who are used to working with markup or a design surface within Visual Studio. Even though Web Parts are server controls, developers are not excluded from building Web Parts as ASP.NET 2.0 user controls (*.ASCX). One option is to use the SmartPart, an open-source project hosted at www.andrewconnell.com/go/238. The SmartPart is a Web Part that acts as a wrapper for user controls. This project effectively lowers the bar of Web Part development, enabling developers to work with visual designers creating user controls instead of adding all rendering logic in a server control.

Jan Tielens, the developer behind the SmartPart, has written a fantastic chapter on the subject of ASP.NET 2.0 user controls for use within Web Parts. See Chapter 7 of Real World SharePoint 2007: Indispensable Experiences from 16 MOSS and WSS MVPs (Wrox, 2007).

The other option is to create a custom Web Part wrapper for a specific user control. The custom Weather ...

Get Professional SharePoint® 2007 Web Content Management Development: Building Publishing Sites with Office SharePoint Server 2007 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.