PersonalizationDictionary.Add Method (String, PersonalizationEntry)

 

Adds personalization entries to the personalization dictionary.

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

public virtual void Add(
	string key,
	PersonalizationEntry value
)

Parameters

key
Type: System.String

The unique identifier for a piece of state information.

value
Type: System.Web.UI.WebControls.WebParts.PersonalizationEntry

A piece of state information to be added to the personalization dictionary. This value can be null.

Exception Condition
ArgumentException

key is a duplicate of a key already in the dictionary.

- or -

key is either an empty string ("") or trimming key results in an empty string.

- or -

value is not a PersonalizationEntry.

ArgumentNullException

key is null.

- or -

value is null.

You can call this method, place various pieces of custom state information into the state object, and specify the scope associated with the state value. When a WebPartManager control is in Shared scope, you can add name and state information that is associated with either Shared scope or User scope. In User scope, you can add name and state information associated only with User scope.

It is a good practice, however, to add all properties to the dictionary using Save including properties with User or Shared scope, regardless of the scope of the page.

The .NET Framework only saves the properties with Shared scope when appropriate. In other words, shared properties are not saved when a WebPart control that was initially added in Shared scope is later saved while the page is in User scope. In an opposite scenario, if a WebPart control was added to the page in User scope, and the control is later saved while the page is in Shared scope, custom shared property values are saved (along with custom user-scoped properties). For details on personalization data and how shared and user-scoped properties are affected by the personalization scope of the page, see the Web Parts Personalization Overview topic.

As with any collection, this method increments the collection count by one and any enumerators currently active on the collection should be invalidated.

.NET Framework
Available since 2.0
Return to top
Show: