Wednesday, April 16, 2008

Web parts

Web parts:

ASP.NET Web Parts is an integrated set of controls for creating Web sites that enable end users to modify the content, appearance, and behavior of Web pages directly from a browser. The modifications can be applied to all users on the site or to individual users. When users modify pages and controls, the settings can be saved to retain a user's personal preferences across future browser sessions, a feature called personalization. These Web Parts capabilities mean that developers can empower end users to personalize a Web application dynamically, without developer or administrator intervention.

There are two basic things in web parts:
• web part manager
• web part zones
WebPartManager
The WebPartManager is the manager for all webparts. If you use webparts in your web projects you are required to use the WebPartManager. Usually you just drag and drop this into your webform and are ready to go
WebPart Zones
There are four kinds of zones in webpart zones:
• WebPart Zone
• Editor Zone
• Catalog Zone
• Connection Zone
WebPart Zone
The webpart Zone is the basic unit for webparts. By placing different contents in a webpart zone we can allow a user to drag and drop contents on a page.
To use different zones add a dropdownlist to your webform and add the following items to it.
• Browse
• Display
• Edit
• Catalog
• Connect
Browse mode
The Browse mode is the default mode of webparts. In Browse mode we can not drag and drop the webparts but we can see two options, minimize and close. Minimizing a webpart will still display it in minimized state. If you choose close then it can only be restored while being in catalog mode which we will discuss later in this article. Here’s a sample webpart being displayed in Browse mode.
2 Design mode
In design mode we can drag drop objects between webparts. There are two webparts named as Links and Search. The following screenshot shows the Links webpart being dragged over the Search one.

Edit Mode
The edit mode is used to edit webparts at runtime. Editing a webpart is further divided into four types: Appearance, Behavior, Property and Layout. We will first see how to use the Appearance and LayoutEditorPart.
AppearanceEditorPart and LayoutEditorPart
First, place an editor zone into the web form. Then place an AppearanceEditorPart and LayoutEditorPart inside the editor zone. Run the application and select the edit mode from the dropdownlist. Click edit from the menu available for webparts.

Catalog mode
The Catalog mode gives us the option to add/remove webparts at runtime. For example if we have few modules like weather, news, shopping, horoscope etc. and want to give the user an option to show or hide these modules at runtime, we can accomplish this task using the catalog mode.
CatalogZone
The CatalogZone is divided into three subtypes: PageCatalogPart, DeclarativeCatalogPart and ImportCatalogPart. On the webform add a CatalogZone and add the previous mentioned three types into it. We can show webparts with the help of the Pagecatalog which are closed by using the close option of the webpart, as seen in following screenshot.
The PagecatalogPart displays the number of webparts which are closed by using this option. The DeclarativeCatalogPart displays the number of elements which are added in design mode to the catalog zone. Click on the smart tag option of the DeclarativeCatalogPart zone and select edit template, then add controls into the catalog zone.

No comments: