This documentation is archived and is not being maintained.

IPersonalizable Interface

Defines additional management capabilities for the application and extraction of personalization state.

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

[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public interface IPersonalizable

In addition to using the Personalizable attribute on control properties, a control can also implement IPersonalizable for additional management capabilities for the application and extraction of personalization state. For example, controls that need to manage private state information should implement this interface. Controls that access personalized data through complex mechanisms, such as custom cache solutions, data persistence to mainframes, or XML Web services, should also implement this interface.

Important noteImportant Note:

You should not add types based on classes defined in the App_Code directory and then depend on the default binary serialization mechanism. App_Code-based artifacts are not consistently binary-serializable due to the fact that they can have their assembly names changed at random points in time.

The following code example demonstrates how to use the IPersonalizable interface. The example consists of an .aspx page that references a Web Part control named UrlListWebPart. The following code is the .aspx file for the example.

<%@ Page Language="C#"  %>
<%@ Register TagPrefix="dict"  
    namespace="Samples.AspNet.CS.Controls" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"  

<html xmlns="" >
<head runat="server">
    <form id="form1" runat="server">
    <asp:WebPartManager ID="mgr" runat="server" />
    <asp:WebPartZone ID="WebPartZone1" runat="server">
        <dict:urllistwebpart id="listwp1" runat="server"
          title="URL List WebPart" />

The following code is the source for the custom WebPart control. This file should be placed in the App_Code directory.

namespace Samples.AspNet.CS.Controls

    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Drawing;
    using System.Web;
    using System.Web.UI;
    using System.Security.Permissions;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;

      Level = AspNetHostingPermissionLevel.Minimal)]
      Level = AspNetHostingPermissionLevel.Minimal)]
    public class UrlListWebPart : WebPart, IPersonalizable
        private ArrayList _sharedUrls;
        private ArrayList _userUrls;
        private bool _listDirty;

        private TextBox _nameTextBox;
        private TextBox _urlTextBox;
        private Button _addButton;
        private BulletedList _list;

        protected override void CreateChildControls()
            Label nameLabel = new Label();
            Label urlLabel = new Label();
            LiteralControl breakLiteral1 = new LiteralControl("<br />");
            LiteralControl breakLiteral2 = new LiteralControl("<br />");
            LiteralControl breakLiteral3 = new LiteralControl("<br />");

            _nameTextBox = new TextBox();
            _urlTextBox = new TextBox();
            _addButton = new Button();
            _list = new BulletedList();

            nameLabel.Text = "Name: ";
            urlLabel.Text = "URL: ";
            _nameTextBox.ID = "nameTextBox";
            _urlTextBox.ID = "urlTextBox";
            _addButton.Text = "Add";
            _addButton.ID = "addButton";
            _addButton.Click += new EventHandler(this.OnClickAddButton);
            _list.DisplayMode = BulletedListDisplayMode.HyperLink;
            _list.ID = "list";





        private void OnClickAddButton(object sender, EventArgs e)
            string name = _nameTextBox.Text.Trim();
            string url = _urlTextBox.Text.Trim();

            Pair p = new Pair(name, url);
            if (WebPartManager.Personalization.Scope == PersonalizationScope.Shared)
                if (_sharedUrls == null)
                    _sharedUrls = new ArrayList();
                if (_userUrls == null)
                    _userUrls = new ArrayList();


        protected virtual void OnUrlAdded()
            _listDirty = true;
            ChildControlsCreated = false;

        protected override void RenderContents(HtmlTextWriter writer)
            if (_sharedUrls != null)
                foreach (Pair p in _sharedUrls)
                    _list.Items.Add(new ListItem((string)p.First, (string)p.Second));
            if (_userUrls != null)
                foreach (Pair p in _userUrls)
                    _list.Items.Add(new ListItem((string)p.First, (string)p.Second));


        public virtual bool IsDirty
                return _listDirty;
        public new virtual void Load(PersonalizationDictionary state)
            if (state != null)
                PersonalizationEntry sharedUrlsEntry = state["sharedUrls"];
                if (sharedUrlsEntry != null)
                    _sharedUrls = (ArrayList)sharedUrlsEntry.Value;

                PersonalizationEntry userUrlsEntry = state["userUrls"];
                if (userUrlsEntry != null)
                    _userUrls = (ArrayList)userUrlsEntry.Value;

        public virtual void Save(PersonalizationDictionary state)
            if ((_sharedUrls != null) && (_sharedUrls.Count != 0))
                state["sharedUrls"] = new PersonalizationEntry(_sharedUrls, PersonalizationScope.Shared);
            if ((_userUrls != null) && (_userUrls.Count != 0))
                state["userUrls"] = new PersonalizationEntry(_userUrls, PersonalizationScope.User);

Load the page in a browser. Type in a name to represent a URL, then add an actual URL beginning with http://, and click the Add button to add the URL.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0