Understand ASP.NET Web Parts
Use standard Web Parts in a Web page
Create a custom Web Part
Use the custom Web Part in a Web page
In Chapters 4 and 5, we took a look at both rendered and composite controls. Chapter 6 covered a few of the controls already available within ASP.NET 2.0. Because rendering an ASP.NET Web form is broken down into small, manageable chunks, arbitrarily extending the framework by adding new controls is a straightforward affair. Server-side controls offer very fine-grained control over the HTML rendered by your application.
In this chapter we get a taste of Web Parts. The topic of Web Parts could take up an entire book—they represent a whole new level of interaction with Web sites. Web Parts are in many ways like custom controls. They give you a way to customize the HTML coming out of your Web site without having to hard-code the output of your page.
While custom controls derive either from System.Web.UI.Control or System.Web.UI.WebControl, Web Parts derive from Microsoft.SharePoint.WebPartPages.WebPart. While WebPart does inherit from System.Web.UI.Control, it goes beyond the regular control functionality by handling interactions with WebPartPage and WebPartZone classes to support adding, deleting, customizing, connecting, and personalizing Web Parts on a page.
One big advantage of using Web Parts is that they combine the flexibility of rendered custom controls with the drag-and-drop manageability of User controls. As a developer you can drag completed Web Parts from Web Parts galleries and drop them onto Web Parts zones. You can modify the shared properties of a group of Web Parts and make them persistent. In addition to being a useful way of packaging UI components, Web Parts can connect with each other via standard interfaces.