1 out of 1 rated this helpful - Rate this topic

PersistenceModeAttribute Class

Defines the metadata attribute that specifies how an ASP.NET server control property or event is persisted to an ASP.NET page at design time. This class cannot be inherited.

System.Object
  System.Attribute
    System.Web.UI.PersistenceModeAttribute

Namespace:  System.Web.UI
Assembly:  System.Web (in System.Web.dll)
[AttributeUsageAttribute(AttributeTargets.All)]
public sealed class PersistenceModeAttribute : Attribute

The PersistenceModeAttribute type exposes the following members.

  Name Description
Public method PersistenceModeAttribute Infrastructure. Initializes a new instance of the PersistenceModeAttribute class.
Top
  Name Description
Public property Mode Gets the current value of the PersistenceMode enumeration.
Public property TypeId When implemented in a derived class, gets a unique identifier for this Attribute. (Inherited from Attribute.)
Top
  Name Description
Public method Equals Infrastructure. Compares the PersistenceModeAttribute object against another object. (Overrides Attribute.Equals(Object).)
Protected method Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method GetHashCode Infrastructure. Provides a hash value for a PersistenceModeAttribute attribute. (Overrides Attribute.GetHashCode().)
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Public method IsDefaultAttribute Infrastructure. Indicates whether the PersistenceModeAttribute object is of the default type. (Overrides Attribute.IsDefaultAttribute().)
Public method Match When overridden in a derived class, returns a value that indicates whether this instance equals a specified object. (Inherited from Attribute.)
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public method ToString Returns a string that represents the current object. (Inherited from Object.)
Top
  Name Description
Public field Static member Attribute Specifies that the property or event persists in the opening tag of the server control as an attribute. This field is read-only.
Public field Static member Default Specifies the default type for the PersistenceModeAttribute class. The default is PersistenceMode.Attribute. This field is read-only.
Public field Static member EncodedInnerDefaultProperty Specifies that a property is HTML-encoded and persists as the only inner content of the ASP.NET server control. This field is read-only.
Public field Static member InnerDefaultProperty Specifies that a property persists as the only inner content of the ASP.NET server control. This field is read-only.
Public field Static member InnerProperty Specifies that the property persists as a nested tag within the opening and closing tags of the server control. This field is read-only.
Top
  Name Description
Explicit interface implemetation Private method _Attribute.GetIDsOfNames Maps a set of names to a corresponding set of dispatch identifiers. (Inherited from Attribute.)
Explicit interface implemetation Private method _Attribute.GetTypeInfo Retrieves the type information for an object, which can be used to get the type information for an interface. (Inherited from Attribute.)
Explicit interface implemetation Private method _Attribute.GetTypeInfoCount Retrieves the number of type information interfaces that an object provides (either 0 or 1). (Inherited from Attribute.)
Explicit interface implemetation Private method _Attribute.Invoke Provides access to properties and methods exposed by an object. (Inherited from Attribute.)
Top

For more information about using attributes, see Extending Metadata Using Attributes.

Note Note

The Web page designer in Visual Studio does not support the ResetPropertyName method that is optionally exposed by Windows Forms controls for property persistence. Server controls are serialized using methods provided by the ControlPersister class. The implementation of these methods is driven by metadata attributes such as DefaultValueAttribute, PersistenceModeAttribute, and DesignerSerializationVisibilityAttribute.


[PersistenceMode(PersistenceMode.InnerProperty),
TemplateContainer(typeof(TemplateItem))]
public ITemplate MessageTemplate {
   get {
      return _messageTemplate;
   }
   set {
      _messageTemplate = value;
   }
}


.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
Collection property in ASPX
To implement custom control with collection property which can be used as follows:
<xxx:TheControl runat="server">
<Items>
<xxx:MyItem Name="Item1"/>
<xxx:MyItem Name="Item2"/>
<xxx:MyItem Name="Item3"/>
</Items>
</xxx:TheControl>

you must implement your class as follows:<ParseChildren(True), PersistChildren(False)>

Public Class TheControl
Inherits Control
Private items As New List(Of MyItem)
<PersistenceMode(PersistenceMode.InnerProperty)>
Public ReadOnly Property Items As List(Of MyItem)
Get
Return items
End Get
End Property
End Class

Public Class MyItem
Public Property Name As String
End Class
Especially important is type of the Items property. It seems that it must be statically typed to type which:
  1. Implements the ICollection non-generic interface
  2. Exposes the Add method
E.g. following types are OK: List(Of T), ObservableCollection(Of T), Collection(Of T), IList
Following types cause various errors: ICollection, ICollection(Of T), IList(Of T), T()

This is minimal C# implementation of class suitable as type of Items property (class implements ICollection and Add):
public class MyCollection : ICollection
{
private ICollection i = newList<Object>();
public void CopyTo(Array array, int index) { i.CopyTo(array, index); }
public int Count { get { return i.Count; } }
public bool IsSynchronized { get { return i.IsSynchronized; } }
public object SyncRoot { get { return i.SyncRoot; } }
public IEnumerator GetEnumerator() { return i.GetEnumerator(); }
public void Add(object o) { ((IList)i).Add(o); }
}
Note: If you want to make it type-safe (or generic), you still have to implement non-generic interface ICollection).
This is valid (at least in C#), too (implementing Add as extension method):
public class MyCollection : ICollection
{
internal ICollection i = newList<Object>();
public void CopyTo(Array array, int index) { i.CopyTo(array, index); }
public int Count { get { return i.Count; } }
public bool IsSynchronized { get { return i.IsSynchronized; } }
public object SyncRoot { get { return i.SyncRoot; } }
public IEnumerator GetEnumerator() { return i.GetEnumerator(); }
}
publicstaticclassMyCollectionExtensions
{
publicstaticvoid Add(thisMyCollection c, object o) { ((IList)c.i).Add(o); }
}