Programming Microsoft Web Forms (Pro Developer)
Display Modes and Web Parts
Recall that the event handler for the drop-down list for Default.aspx in the WebParts project changed the DisplayMode property of the WebPartManager1 object. The DisplayMode property must be one of the WebPartDisplayMode enumerations, as outlined in Table 4-3.
DisplayMode Property | Description |
---|---|
BrowseDisplayMode | Displays Web Parts for normal, end user use. This is the default mode. |
DesignDisplayMode | Displays the Web Part zone user interface (UI), enabling users to drag and drop Web Part components to change the layout of the page. |
EditDisplayMode | Displays special editing UI elements and allows end users to edit the controls on the page. |
CatalogDisplayMode | Displays a special catalog UI to allow end users to add and remove page controls. |
ConnectDisplayMode | Displays a special connections UI to allow end users to connect Web Part controls. |
Browse, Design, and Catalog are the three display modes you will use most. The BrowseDisplayMode enumeration can be seen in Figure 4-1, and the DesignDisplayMode enumeration can be seen in Figure 4-2 and Figure 4-3. To use the CatalogDisplayMode enumeration, you must first close one of the Web Parts on the page. In Figure 4-6, the menu for one of the Web Parts appears on the Default.aspx page.
When you click Close, the page appears as shown in Figure 4-7.
The first thing I noticed when I first played with Web Parts is that when you close a Web Part, it stays closed! The state of the page is saved, even if you have not logged in to the site. This is known, rather oddly, as anonymous personalization.
To get the closed Web Part back, you must enter Catalog mode. In Default.aspx, select Catalog from the drop-down list, and the page appears as shown in Figure 4-8.
The interesting portion of the page is the Page Catalog inside of the Catalog Zone. Untitled [1] is in the list of Web Parts in the catalog. When you select the check box next to Untitled [1] and click Add, the Web Part is added to the selected zone, WebPartZone1, as shown in Figure 4-9.