12.5. Building a Custom Web Part with AJAX

When adding items to a page that utilizes the Portal Framework, you add the preexisting ASP.NET Web server controls, user controls, or custom controls. In addition to these items, you can also build and incorporate custom Web Parts. Using the WebParts class, you can create your own custom Web Parts. Although similar to ASP.NET custom server control development, the creation of custom Web Parts provides some additional capabilities. Creating a class that inherits from the WebPart class instead of the Control class enables your control to use the new personalization features and to work with the larger Portal Framework, thereby allowing for the control to be closed, maximized, minimized, and more.

To create a custom Web Part control, the first step is to create a project in Visual Studio 2008. From Visual Studio, choose File New Project. This pops open the New Project dialog. In this dialog, select ASP.NET Server Control. Name the project MyStateListBox, and click OK to create the project. You are presented with a class that contains the basic framework for a typical ASP.NET server control. Ignore this framework; you are going to change it so that your class creates a custom Web Parts control instead of an ASP.NET custom server control. Listing 12-4 details the creation of a custom Web Part control that incorporates the use of AJAX.

Example ...

Get Professional ASP.NET 3.5 AJAX 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.