Introduction:
This tutorial considered to be the second part of the first tutorial Creating a Simple WebPart Page and use WebServer controls as WebParts. Here we will see how can we remove and add WebParts during run time, adding personalizable properties to your WebParts and modifying there values also in run time.
WebPart Zones:
There are 4 types of WebPart Zones. Zones is used to host (anchor or dock) WebParts. In the previous tutorial we had a look at WebPartZone. At this tutorial we will have a look at the other another two WebPart Zones, CatalogZone & EditorZone.
Modification to old project:
In the new project, have cut the XmlDataSource control -xdsRSS- and the DataList Control -dlstRss- to a newly created UserControl named UCtrlRSSReader.ascx. The same I did for SqlDataSource control -sdsTitles- and the GridView Control -gvTitles- which were saved on the UserControl UCtrlTitles.ascx.
Working with the CatalogZone:
Open the pervious project and apply the following modifications:
- Add another column to the table, so the table will contain 4 columns now.
- Drag and drop CatalogZone Control from control from the Toolbox (under the WebParts tab) into the new column cell, rename it to wpczCatalog and set its Auto format to Colorful.
- Drag and drop PageCatalogPart Control into the CatalogZone Control wpczCataog, rename it wpcPageCatalog.

- Drag and drop DeclarativeCatalogPart Control into the CatalogZone Control wpczCataog, rename it wpcDeclarativeCatalog.
- From DeclarativeCatalogPart Tasks smart tag, Select Edit Template.
- Then drag and drop UCtrlRSSReader from your solution explorer into the WebPartsTemplate area of wpcDeclarativeCatalog control, and click End Template Editing in the smart tag.
- Switch to Source view and add Title attribute to your UserControl you have just dropped, set its value to "RSS Reader". Be careful to edit the correct control:

- Drag and drop a DropDownList into your Web From but out of the table area, rename it to cmbWebPartPageMenu. Then add the following items to it.
Normal View
Design View
Edit View
Manage WebParts
- Set the AutoPostBack property of the DropDownList Control to true. and double click on it to implement it default event SelectedIndexChanged:
protected void cmbWebPartPageMenu_SelectedIndexChanged(object sender, EventArgs e)
{switch (cmbWebPartPageMenu.SelectedIndex)
}
{case 0:
}wpManager.DisplayMode = WebPartManager.BrowseDisplayMode;
case 1:
break;wpManager.DisplayMode = WebPartManager.DesignDisplayMode;
case 2:
break;wpManager.DisplayMode = WebPartManager.EditDisplayMode;
case 3:
break;wpManager.DisplayMode = WebPartManager.CatalogDisplayMode;
case 4:
break;wpManager.DisplayMode = WebPartManager.ConnectDisplayMode;
default:
break;wpManager.DisplayMode = WebPartManager.BrowseDisplayMode;
break;
- Now run your page, select Manage WebParts option and note the changes on the page.

Click on Declarative Catalog link and notice the the deference.
For any WebPart on the the page, click on its menu at the top right corner, and select Close. Notice the changes on the Catalog Zone. you will fine the Page Catalog is increased. Click on Page Catalog link and notice the change on the zone. You can add any WebPart listed to your page, by checking the checkbox of the WebPart, selecting the WebPart Zone and then click Add.

Narasimhan SrinivasaneditedPosted Mar 5, 2010, 7:56 AMEdited Mar 5, 2010, 7:57 AM
I am getting the sql error. while running the application i am getting the sql server has failed to connect to the host server and then i have tried with xml but i am getting the same error. please provide a solution to overcome from the error.
abdul_sami_20Posted Dec 17, 2009, 8:48 AM
http://www.codeproject.com/KB/aspnet/IntroToWeb_Parts.aspx
vinod vinodPosted Dec 3, 2007, 5:28 AM
Hi! This article is very usefull to all. If i once close the control using web parts after Whene i try to resume the control it dint resume please help me. Thanks Celva B