WebPart.SaveProperties property

Gets or sets a value that indicates whether the properties of a Web Part have changed and should be persisted at the end of page rendering.

Namespace:  Microsoft.SharePoint.WebPartPages
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

protected internal bool SaveProperties { get; set; }

Property value

Type: System.Boolean
true if the Web Part properties should be persisted; otherwise, false.

The SaveProperties property is initially set to false at the beginning of page rendering. This property is useful only during page rendering. For example, this property has no effect when a Web Part is accessed through the object model.

The SaveProperties property can be used for Web Parts when their properties change after being rendered in a Web Part Page. After a property is changed, a WebPart class can set the SaveProperties property to true to specify that any changed properties will be saved. The value of the SaveProperties property is read by the Web Part infrastructure after the System.Web.UI.Control.UnLoad event of the Web Part occurs, at which point all property values are queried and stored in the SharePoint database. If this property is not set, the properties revert to their original values the next time the Web Part is instantiated.

The value of the SaveProperties property is ignored unless a Web Part is actively being rendered. For example, instantiating a new Web Part, changing a property value, and then setting SaveProperties to true has no effect. The SaveProperties property should be used by a Web Part that needs to save a property that has changed after being rendered. If a property is set externally, it is the responsibility of the external agent to either save the Web Part explicitly, or during a render cycle to set the SaveProperties property on behalf of the Web Part.

If the SaveProperties property is set on a static Web Part (a Web Part that is not located in a zone), or for a Web Part where the user does not have sufficient permissions to save changes (such as for an anonymous user), an exception is thrown when an attempt is made to save that Web Part. A Web Part should check the Permissions property before displaying a user interface for saving property values and setting SaveProperties to true.

To view a code sample that provides an example of how to use the SaveProperties property, see WebPart.