Datasheet

By taking advantage of Web Parts, you, as a developer, can empower your users with the ability to
perform the following operations.
Users can personalize page content.
Users can personalize the page layout by allowing the users to drag Web Parts from one zone to
another zone, or change its appearance, look and feel, and so on.
Users can also export and import Web Part controls so the Web Parts can be effectively shared
among other sites.
Users can create connections between two Web Parts by establishing communication between
Web Part controls.
As a developer, you will typically work with Web Parts in one of the three ways: creating pages that use
Web Parts controls, creating individual Web Parts controls, or creating complete personalizable web por-
tals. You can create two kinds of Web Parts in ASP.NET 2.0:
Custom Web Part: Those Web Part controls that derive from the System.Web.UI
.WebControls.WebParts.WebPart
class.
Generic Web Part: A custom control that does not inherit from the WebPart class and is still
used as a Web Part is called
GenericWebPart. For example, if you place a TextBox control
inside a
WebPartZone control (a zone on the page that hosts the Web Parts control), the
TextBox control will be wrapped to a GenericWebPart class.
This section provides you with a simple generic Web Part creation example followed by a code examina-
tion. Listing 1-3 shows the code required to implement the Web Part.
Listing 1-3: Creating a Simple Generic Web Part
<%@ Page Language=”C#” %>
<html xmlns=”http://www.w3.org/1999/xhtml” >
<head runat=”server”>
<title>Example of a GenericWebPart</title>
</head>
<body>
<form id=”form1” runat=”server”>
<asp:WebPartManager id=”WebPartManager1” runat=”Server”>
</asp:WebPartManager>
<table cellspacing=”0” cellpadding=”0” border=”0”>
<tr>
<td valign=”top”>
<asp:WebPartZone id=”MainZone” runat=”server”
headertext=”Main”>
<ZoneTemplate>
<asp:Label id=”contentPart” runat=”server”
title=”GenericWebPart”>
<h4>GenericWebPart that uses a label control
to generate the contents of the Web Part
</h4>
</asp:Label>
</ZoneTemplate>
</asp:WebPartZone>
</td>
14
Part I: Introduction
05_041796 ch01.qxp 12/29/06 9:09 PM Page 14