Partager via


Using the Web Part Class Constructor

If you are working with a Web Part base class property, the easiest way to set default values is to set the initial values for properties in the class constructor. When properties are saved, the Web Part infrastructure compares the values of all properties against the values the properties had after the derived class constructor ran. If they match, it is assumed that the property has the default value, and the property value should be persisted. If they do not match, the property values are stored in the Microsoft® Windows® SharePoint™ Services database.

Defining default property values in the class constructor cannot be done with custom properties—this comparison is only made for base class properties.

For a complete list of base class properties, see the WebPart class.