concept web part in category asp.net

This is an excerpt from Manning's book ASP.Net 2.0 Web Parts in Action: Building Dynamic Web Portals.
The portal example we are about to create will consist of a single web page that has two zones: a zone on the left side of the page and another on the right side. Each zone will contain a single web part. The page will also have a button which enables the user to switch the page into a mode that allows the web parts to be moved between the two zones. When web parts are in this mode, properties, such as their titles, can be edited at runtime. Figure 1.2 shows what our example page will look like when it is complete, and highlights some of the key points.
You may already be acquainted with web parts and web part controls, and if you’ve worked with products such as SharePoint you have already used them quite extensively. (If these topics are not familiar, please dip into chapter 1 for a quick refresher.) Before you start this chapter, I recommend that you whet your appetite by seeing real examples of how web part controls allow users to customize the look and feel of web applications. To do so, visit http://Start.com. This is a web-based portal created by Microsoft Research. Notice how it provides a variety of methods to customize the page, by adding web parts and configuring them. For example, while at that page you could add a web part to display the current news from one of a dozen news providers, or display the weather for any city in the world. If you’re like me, you could lose many hours configuring that page to exactly suit your fancy. And guess what—once you’ve done it, it’s your page! Every time you visit that page, all the web parts you added, configured, and moved around will be there for you—just the way you left them.
In chapter 1 we learned that web parts are an integral aspect of a portal application. This chapter supplies a more exhaustive understanding of web parts, in particular how they are implemented in ASP.NET 2.0 portal applications.
This chapter is the first step in a journey through the properties, methods, and operations of web parts. In it we’ll learn how to add custom verbs to web parts and how to customize their look and feel through themes and other customization techniques. We’ll also delve a little deeper into the subject to see how web parts implement various interfaces that expose their behavior to the rest of the ASP.NET web portal framework. By the end of this chapter we’ll be well on our way to understanding how the http://Start.com website achieves its magic. Let’s begin!
Open your test project and create a new web page named GenericWebPartTest.aspx. This page will be used to learn how these web controls are turned into web parts. As with all web pages that contain web parts, we must start by adding a WebPartManager control at the top of the page. Finally, we can add a WebPartZone and add a Label control to it. With that, our code should look like the following snippet:
<asp:WebPartManager ID="WebPartManager1" runat="server" /> <asp:WebPartZone ID="WebPartZone1" runat="server"> <ZoneTemplate> <asp:Label id="ctl1" runat="server" Text="I'm a label" /> </ZoneTemplate> </asp:WebPartZone>All that we know at this stage is that at some time between now and when this page is displayed in a browser, the Label control that we added to the web part zone starts looking and behaving like a web part. We know this because we saw that the label gained two characteristics common to web parts—a Title and Verbs—when it was contained within the web part zone in the previous chapter. Next we‘ll write code that allows us to view the state of the page at runtime. Switch into the code section of the web page, enter the code, and set the debugging breakpoints that are displayed in figure 2.2.
Web parts are informational components, such as news updates or comics, that are added to web pages; and as such, web parts can be considered the primary building blocks of a portal application that displays dynamic content. In ASP.NET 2.0 we are provided with the WebPart server control for working with web parts. The WebPart server control comes pre-packaged with many properties and methods needed to use it in a variety of ways to show dynamic content to users.
A web part is generally rendered with a title bar, a border, and a body for displaying its dynamic content. The web part is manipulated by a web control that allows a user to work with and customize the web part. For example, users can set the web part’s height or width and provide it with a title and description. Other manipulations of web parts are accessed through small menu-like items known as verbs. These operations include performing tasks such as closing the web part, minimizing it, or connecting it to other web parts on the page. Figure 2.1 shows the basic elements that make up a standard web part control.
In figure 2.1 we can see the various sub-elements that combine to form a web part. Throughout this chapter we will learn more about each of these elements and see how to use the WebPart class to modify or affect each different element. Understanding how to gain access to each of these elements will take us a long way down the path towards having full control over how our web parts are displayed to the end-users of our portal.