.NET Framework Class Library
PersonalizableAttribute Class

Represents the personalization attribute. This class cannot be inherited.

Inheritance Hierarchy
SystemObject
   SystemAttribute
    System.Web.UI.WebControls.WebPartsPersonalizableAttribute

Namespace:   System.Web.UI.WebControls.WebParts
Assembly:  System.Web (in System.Web.dll)
Syntax
<[%$TOPIC/kz98xy1t_en-us_VS_110_2_0_0_0_0%]([%$TOPIC/kz98xy1t_en-us_VS_110_2_0_0_0_1%].Property)> _
Public NotInheritable Class PersonalizableAttribute _
	Inherits [%$TOPIC/kz98xy1t_en-us_VS_110_2_0_0_0_2%]
[[%$TOPIC/kz98xy1t_en-us_VS_110_2_0_1_0_0%]([%$TOPIC/kz98xy1t_en-us_VS_110_2_0_1_0_1%].Property)]
public sealed class PersonalizableAttribute : [%$TOPIC/kz98xy1t_en-us_VS_110_2_0_1_0_2%]
[[%$TOPIC/kz98xy1t_en-us_VS_110_2_0_2_0_0%]([%$TOPIC/kz98xy1t_en-us_VS_110_2_0_2_0_1%]::Property)]
public ref class PersonalizableAttribute sealed : public [%$TOPIC/kz98xy1t_en-us_VS_110_2_0_2_0_2%]
[<[%$TOPIC/kz98xy1t_en-us_VS_110_2_0_3_0_0%]>]
[<[%$TOPIC/kz98xy1t_en-us_VS_110_2_0_3_0_1%]([%$TOPIC/kz98xy1t_en-us_VS_110_2_0_3_0_2%].Property)>]
type PersonalizableAttribute =  
    class 
        inherit [%$TOPIC/kz98xy1t_en-us_VS_110_2_0_3_0_3%] 
    end

The PersonalizableAttribute type exposes the following members.

Constructors
  NameDescription
Public method PersonalizableAttributeInitializes a new instance of the PersonalizableAttribute class.
Public method PersonalizableAttribute(Boolean)Initializes a new instance of the PersonalizableAttribute class using the provided parameter.
Public method PersonalizableAttribute(PersonalizationScope)Initializes a new instance of the PersonalizableAttribute class using the provided parameter.
Public method PersonalizableAttribute(PersonalizationScope, Boolean)Initializes a new instance of the PersonalizableAttribute class using the provided parameters.
Top
Properties
  NameDescription
Public property IsPersonalizableGets the setting that indicates whether the attribute can be personalized, as established by one of the constructors.
Public property IsSensitiveGets the setting that indicates whether the attribute is sensitive, as established by one of the constructors.
Public property ScopeGets the PersonalizationScope enumeration value for the class instance, as set by one of the constructors.
Public property TypeIdWhen implemented in a derived class, gets a unique identifier for this Attribute. (Inherited from Attribute.)
Top
Methods
  NameDescription
Public method EqualsWhen overridden, returns a Boolean evaluation of the current instance of PersonalizableAttribute and another PersonalizableAttribute instance supplied as a parameter. (Overrides AttributeEquals(Object).)
Public method GetHashCodeWhen overridden, returns a hash code of the attribute. (Overrides AttributeGetHashCode.)
Public method Static member GetPersonalizablePropertiesReturns a collection of PropertyInfo objects for the properties that match the parameter type and are marked as personalizable.
Public method GetTypeGets the Type of the current instance. (Inherited from Object.)
Public method IsDefaultAttributeWhen overridden, returns a value that indicates whether the attribute instance equals the value of the static Default field. (Overrides AttributeIsDefaultAttribute.)
Public method MatchReturns a value that indicates whether the current instance of PersonalizableAttribute and the specified PersonalizableAttribute have the same IsPersonalizable property value. (Overrides AttributeMatch(Object).)
Public method ToStringReturns a string that represents the current object. (Inherited from Object.)
Top
Fields
  NameDescription
Public field Static member DefaultReturns an attribute instance that indicates no support for personalization. This field is read-only.
Public field Static member NotPersonalizableReturns an attribute instance that indicates no support for personalization. This field is read-only.
Public field Static member PersonalizableReturns an attribute instance that indicates support for personalization. This field is read-only.
Public field Static member SharedPersonalizableReturns an attribute instance that indicates support for personalization with a shared scope. This field is read-only.
Public field Static member UserPersonalizableReturns an attribute instance that indicates support for personalization in User scope. This field is read-only.
Top
Explicit Interface Implementations
  NameDescription
Explicit interface implemetation Private method _AttributeGetIDsOfNamesMaps a set of names to a corresponding set of dispatch identifiers. (Inherited from Attribute.)
Explicit interface implemetation Private method _AttributeGetTypeInfoRetrieves 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 _AttributeGetTypeInfoCountRetrieves the number of type information interfaces that an object provides (either 0 or 1). (Inherited from Attribute.)
Explicit interface implemetation Private method _AttributeInvokeProvides access to properties and methods exposed by an object. (Inherited from Attribute.)
Top
Exceptions
ExceptionCondition
HttpException

The property is a read-only or write-only public property.

- or -

The property is a private or protected read/write property.

- or -

The property has index parameters.

Remarks

The personalization attribute, Personalizable, is applied to public control properties that need to persist personalization information. ASP.NET automatically generates the code to persist or retrieve these values from the underlying data store when the control is in a Web Parts zone on a Web Parts page.

The following requirements must be met for a property to be marked as personalizable:

  • The property must be public and must have public get and set accessors.

  • The property must be a read/write property.

  • The property must be without parameters.

  • The property cannot be indexed.

Code is automatically generated to load and save personalization data for properties. Properties that support personalization are determined based on the existence of this attribute on the property and the fact that the property conforms to the constraints listed above.

Note that read-only and write-only properties are not supported for personalization. Applying this attribute to a read-only or write-only property results in an HttpException being thrown. Parameterized properties also throw an HttpException exception.

Individual properties without this attribute are excluded from personalization if no special handling through the IPersonalizable interface is used.

For more information about using attributes, see Web Parts Personalization Overview.

Examples

The following code example demonstrates how to use the PersonalizableAttribute class in code. The sample consists of an .aspx page that references a Web Part user control called ColorSelector.ascx. The following code is the .aspx file for the example.

<%@ Page Language="C#"  %>
<%@ Register TagPrefix="uc1" TagName="colorcontrol" Src="ColorSelector.ascx" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>

<body>
    <form id="form1" runat="server">
      <div>
        &nbsp;<asp:LoginName ID="LoginName1" runat="server" />
        &nbsp;
        <asp:LoginStatus ID="LoginStatus1" runat="server" LogoutAction="RedirectToLoginPage" />
        &nbsp;&nbsp;&nbsp;&nbsp;<br />
        <br />
        &nbsp;<asp:WebPartManager ID="WebPartManager1" runat="server">
        </asp:WebPartManager>

    </div>
        <asp:WebPartZone ID="WebPartZone1" runat="server"  Height="200" Width="200">
        <ZoneTemplate>
        <uc1:colorcontrol id="colorcontrol" runat="server" />
        </ZoneTemplate>
        </asp:WebPartZone>        
    </form>
</body>
</html>

The following code is for the ColorSelector.ascx control.

Security noteSecurity Note

This example has a text box that accepts user input, which is a potential security threat. By default, ASP.NET Web pages validate that user input does not include script or HTML elements. For more information, see Script Exploits Overview.

<%@ Control Language="C#" %>

<script runat="server">
private System.Drawing.Color userchoice;

[Personalizable]
public System.Drawing.Color UserColorChoice
{
   get
   {
     return userchoice;
   }
   set
   {
     userchoice = value;
   }
}

protected void OnRed(object src, EventArgs e)
{
  _color.BackColor = System.Drawing.Color.Red;
  UserColorChoice = System.Drawing.Color.Red;
}

protected void OnGreen(object src, EventArgs e)
{
  _color.BackColor = System.Drawing.Color.Green;
  UserColorChoice = System.Drawing.Color.Green;
}

protected void OnBlue(object src, EventArgs e)
{
  _color.BackColor = System.Drawing.Color.Blue;
  UserColorChoice = System.Drawing.Color.Blue;
}

protected void Page_Init(object src, EventArgs e)
{
  _redButton.Click   += new EventHandler(OnRed);  
  _greenButton.Click += new EventHandler(OnGreen);  
  _blueButton.Click  += new EventHandler(OnBlue);  
}

protected void Page_Load(object src, EventArgs e)
{
  if (!IsPostBack)
  {
          _color.BackColor = UserColorChoice;
  }
}

</script>
<body>
    <div>
        <asp:TextBox ID="_color" runat="server" Height="100" Width="100" />
        <br />
        <asp:button runat="server"  id="_redButton" text="Red"  /> 
        &nbsp;&nbsp;
        <asp:button runat="server"  id="_greenButton" text="Green" />
        &nbsp;&nbsp;
        <asp:button runat="server" id="_blueButton" text="Blue" />
    </div>
</body>
Version Information

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0
Platforms

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.