Introduction to Editor Parts...
Web parts are reusable pieces of code that are logically grouped together into one unit. They can be a single standard .NET server control, a web user control, or a custom control. Editor part controls can be used to change the design and layout of web parts in the browser at runtime.
Web parts are reusable pieces of code that are logically grouped together into one unit. They can be a single standard .NET server control, a web user control, or a custom control. Editor part controls can be used to change the design and layout of web parts in the browser at runtime. These controls edit the default properties made available through the web part framework, which are retained through the personalization provider. Some of the properties available from the editors include: title, height, width, chrome type, direction, zone index, and many other properties. The .NET framework offers several editor parts out of the box:
AppearanceEditorPart – This editor part alters the title, width, height, chrome type, and other properties
of existing editor parts.
BehaviorEditorPart – This editor part alters the visibility of verbs (close, minimize, restore, etc.),
as well as editing the description and images used in the web part.
LayoutEditorPart – This editor part changes the location of an editor part, through the zone name or the
zone index.
PropertyGridEditorPart – This editor part edits custom properties; this editor will be discussed in a
future article.
Web parts exist within a "zone", a container control that can contain one or more web parts. Zones define regions within the application that web parts must belong in. They also define user interface features of web parts, such as title color and style, as well as the availability of web part verbs (standard or customizable actions that can be performed for web parts and zones, such as the Close or Minimize verbs). Editor parts can only appear within an editor zone, and no other type. This is the same for other types of zones; web parts can only appear in web part zones, as well as catalog parts can only appear in catalog zones.
When editor parts are available in an application, the WebPartPageMenu control has an additional list option for editing the web part properties. This option ("Modify the Web Part Settings") renders a down arrow image within the web part title bar. Clicking this bar displays a menu list with hyperlinks, which one of them is the "Edit" link. The link displays the editor zone with all of the available web parts.
Editor parts can be customized for an application. The EditorPart class contains all of the base functionality required for custom editor parts. Similar to other control building, by overriding the CreateChildControl or RenderContents methods, a custom editor part can be rendered to the screen that is completely customizable for the application. The editor part is then linked to a specific web part control to edit its properties using any controls available in the .NET framework. This will be discussed further in a future article.
Let's look at a simple example of editor parts. Using the same example code as the Web Part Introduction article, this example adds an editor zone, which contains editor parts described above. The declaration is shown below:
|
<asp:EditorZone ID="EditorZone1" Runat="server" VerbButtonType="Image" PartChromeType="TitleOnly"> <PartTitleStyle ForeColor="#666644"></PartTitleStyle> <PartChromeStyle Font-Bold="True" BorderColor="#804000" BackColor="#FFFFC0" ForeColor="Green"></PartChromeStyle> <PartStyle BorderWidth="0px"></PartStyle> <ZoneTemplate> <asp:AppearanceEditorPart ID="aep" Runat="server" ScrollBars="Vertical" ToolTip="Modify the appearance of the web part." Description="Alters the appearance of the application." /> <asp:BehaviorEditorPart ID="bep" Runat="server" ScrollBars="Vertical" ToolTip="Modify the behavior of the web part." /> <asp:LayoutEditorPart ID="lep" Runat="server" ScrollBars="Vertical" ToolTip="Modify the layout of the web part." /> </ZoneTemplate> </asp:EditorZone> |
That's all that is needed to edit web parts at runtime in the application. Run the sample application and choose the "Modify the Web Part Settings" option in the WebPartPageMenu control. Edit a web part by clicking the down arrow, and choose "Edit" in the dynamic menu list. The editor zone appears, allowing the application user to make any necessary modifications. There is no coding required for invoking the editor parts, and to retain the settings. This is all done through the framework and the personalization provider.
You may download the code here.