PersistenceMode 枚举


指定在 .aspx 或 .ascx 文件中如何以声明方式保持 ASP.NET 服务器控件的属性或事件。Specifies how an ASP.NET server control property or event is persisted declaratively in an .aspx or .ascx file.

public enum class PersistenceMode
public enum PersistenceMode
type PersistenceMode = 
Public Enum PersistenceMode


Attribute 0

指定属性或事件保持为特性。Specifies that the property or event persists as an attribute.

EncodedInnerDefaultProperty 3

指定属性作为 ASP.NET 服务器控件的唯一内部文本而进行保持。Specifies that the property persists as the only inner text of the ASP.NET server control. 属性值是 HTML 编码的。The property value is HTML encoded. 只能对字符串做这种指定。Only a string can be given this designation.

InnerDefaultProperty 2

指定属性在 ASP.NET 服务器控件中保持为内部文本。Specifies that the property persists in the ASP.NET server control as inner text. 还指示将该属性定义为元素的默认属性。Also indicates that this property is defined as the element's default property. 只能指定一个属性为默认属性。Only one property can be designated the default property.

InnerProperty 1

指定属性在 ASP.NET 服务器控件中保持为嵌套标记。Specifies that the property persists in the ASP.NET server control as a nested tag. 这通常用于复杂对象,它们具有自己的持久性属性。This is commonly used for complex objects, those that have persistable properties of their own.


下面的代码示例演示一个 ITemplate 属性,该属性将保留为内部属性,这是通过将 PersistenceModeAttribute 属性应用于属性的元数据来定义的。The following code example demonstrates an ITemplate property that will be persisted as an inner property, as defined by applying the PersistenceModeAttribute attribute to the property's metadata.

public ITemplate MessageTemplate {
   get {
      return _messageTemplate;
   set {
      _messageTemplate = value;

<PersistenceMode(PersistenceMode.InnerProperty), TemplateContainer(GetType(TemplateItem))> Public Property MessageTemplate() As ITemplate
      Return _messageTemplate
   End Get
   Set(ByVal Value As ITemplate)
      _messageTemplate = Value
   End Set
End Property