AllowEdit Property

WebPart.AllowEdit Property


Gets or sets a value indicating whether an end user can modify a WebPart control through the user interface (UI) provided by one or more EditorPart controls.

Namespace:   System.Web.UI.WebControls.WebParts
Assembly:  System.Web (in System.Web.dll)

public virtual bool AllowEdit { get; set; }

Property Value

Type: System.Boolean

true if the WebPart control can be modified; otherwise, false. The default value is true.

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.

For an example that uses EditorPart controls from the Web Parts control set and shows how to enable editing of a custom Web Parts control, see Walkthrough: Creating a Web Parts Page.


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.

This property cannot be set by themes or style sheet themes. For more information, see ThemeableAttribute and ASP.NET Themes and Skins.

The personalization scope of this property is set to Shared and can be modified only by authorized users. For more information, see PersonalizableAttribute and 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.

.NET Framework
Available since 2.0
Return to top
© 2015 Microsoft