When the Persistence manager is looping through the controls in a page by default it saves all of them. This also means that all the control properties are persisted by default. In a case when you want to persist just some of the properties or want to avoid saving some, you can remove them from the persisted data. The Persistence API provides a class that holds the properties data called pick:[asp-net="* PropertyData*"] . By excluding some of the properties you reduce the size of the persisted data which sometimes is crucial for the available resources.
Note
|
Note:
You also may want to remove properties for security reasons. |
You can remove the unnecessary control properties while handling the pick:[asp-net="* PersistenceSaved*"] event. When you want to remove control from the persisted data, as it is in Exclude Control, the control found by its ID, but when you want to remove just a property you need the property’s name. Therefore you must specify a list of strings that contains the names of the properties to be ignored.
In C#: |
---|
protected void PersistenceSaved(object sender, PersistenceEventArgs e) { if (e.PersistenceData == null) { return; } List<string> listIgnoredControlsID = new List<string>() { this.control1.ID }; List<string> listIgnoredPropertiesID = new List<string>() { "prop1", "prop2" }; PersistenceData data = e.PersistenceData; ControlData controlToRemove = null; foreach (string ignoredControlID in listIgnoredControlsID) { controlToRemove = data.Controls.Find(delegate(ControlData controlToFind) { return controlToFind.ControlId == ignoredControlID; }); if (controlToRemove != null) { this.RemovePropertiesFromControl(controlToRemove, listIgnoredPropertiesID); controlToRemove = null; } } this.StoredData = data.ToJson(); } private void RemovePropertiesFromControl(ControlData controlToRemove, List<string> listIgnoredPropertiesID) { PropertyData propertyToRemove = null; foreach (string ignoredPropertyID in listIgnoredPropertiesID) { propertyToRemove = controlToRemove.Properties.Find( delegate(PropertyData propertyToFind) { return propertyToFind.Name == ignoredPropertyID; }); if (propertyToRemove != null) { controlToRemove.Properties.Remove(propertyToRemove); propertyToRemove = null; } } } |