10.2. Creating Custom Field Types and Controls

Creating a custom field type and field control requires creating numerous classes and files, packaging everything up, and deploying files to numerous locations. The following sections explain each of the components in Figure 10-1 in more depth, as they demonstrate how to create a custom field type and field control. First, it helps to see what the final result will look like and review the requirements for the field type and control.

The custom field type (CountryRegionField) and control (CountryRegionControl) that are built in this chapter enable a content author to select a country and then enter a state/region depending on the country selected. Initially, no country or state/region is selected. In fact, when no country is selected, the controls to select or enter the state/region are not shown. Upon selecting "United States," the page will issue a postback and refresh, presenting the content author with another selector to pick a state. If the content owner selects a country other than "United States," then the page issues a postback and renders a textbox to enter the region/county, rather than select a state from a selector. Figures 10-2 and 10-3 show what the field control looks like when editing a page in a Publishing site with "United States" or "United Kingdom" selected as the country, respectively.

Figure 10-2. Figure 10-2
Figure 10-3. Figure 10-3

In Display mode (when a page is not in Edit mode), the state/region should ...

Get Professional SharePoint® 2007 Web Content Management Development: Building Publishing Sites with Office SharePoint Server 2007 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.