To allow end users to edit a WebPart control, the AllowEdit property must be set to true (the default), and the page's display mode must be in edit mode. Display modes are represented by fields in the WebPartManager control. In this case, the mode is EditDisplayMode. For details about page display modes and how to change them, see the WebPartDisplayMode class overview.
When the AllowEdit property is set to false either declaratively or programmatically, editing options are limited. The only possible editing operations are changes to the page's layout, using a LayoutEditorPart control, or other basic operations enabled through custom EditorPart controls.
The effect that the AllowEdit property has on a control's behavior is also impacted by the current personalization scope of the Web page, and the individual Web Parts controls on that page. For more information, see Web Parts Personalization Overview.
The following code example demonstrates how to change the default setting of the AllowEdit property for a Web Parts control, so that the control cannot be edited. This example assumes the use of a WebPart control, TextDisplayWebPart, which is found in the Example section of the WebPart class overview.
The code example also uses a custom user control that enables users to change display modes on a Web Parts page. The user control is referenced by means of a Register directive near the top of the Web page that hosts the user control. For a detailed description of how to create this user control and work with display modes, see Walkthrough: Developing and Using a Custom Web Server Control.
In the declarative markup for the Web page, on the <aspSample:TextDisplayWebPart> element that references the control, note the AllowEdit="false" attribute. Although true is the default, the attribute has been set to false for the purposes of this example. Load the page in a browser and use the Display Modes drop-down list control to change the display mode to edit mode. Next, click the verbs menu in the title bar of the WebPart control, and note that the edit verb is missing, because you disabled editing on the control.