This documentation is archived and is not being maintained.

WebPartManager.IPersonalizable.IsDirty Property

Gets a value that indicates whether custom personalization state data managed by the WebPartManager control has changed on a Web page.

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

bool IPersonalizable.IsDirty { get; }

Property Value

Type: System.Boolean
A Boolean value that indicates whether the personalization state data has changed.



The IPersonalizable.IsDirty property provides a way for callers to determine whether personalization state data that is managed by the WebPartManager control has changed. When users personalize page-level details, for example by changing page layout, creating or deleting connections, and adding or deleting controls, the personalization data managed by the WebPartManager control changes. This is a pass-through method that returns to callers the value of the protected IsCustomPersonalizationStateDirty property, which cannot be directly accessed by callers.


The IPersonalizable.IsDirty property does not indicate whether personalizable property values, or individual properties that affect the appearance of individual WebPart controls, have changed. Control-level personalization is tracked for each control individually. The IPersonalizable.IsDirty property indicates only whether personalization data that is at the page level and is managed by the WebPartManager control has changed.

The following list describes some common instances of personalization that would cause the IPersonalizable.IsDirty property to return a value of true, indicating that the WebPartManager control has some changed personalization data:

  • Closing a static WebPart control (or server or user control) on a page.

  • Restoring a closed static WebPart control from a page catalog back to a page.

  • Moving any control within its zone or to another zone.

  • Adding a control from a catalog of WebPart or server controls, or adding a control programmatically.

  • Creating a connection between two WebPart controls, either programmatically or by using the connection user interface (UI).

  • Deleting a connection between two WebPart controls, either programmatically or by using the connection UI.

To access this property value, you must cast the WebPartManager control instance to the IPersonalizable interface; you can then read the IsDirty property value.

The following code example demonstrates a simple usage of the IPersonalizable.IsDirty property, to indicate some common page personalization instances that cause a WebPartManager control's personalization data to change.

The code example has four parts:

  • A user control that allows you to change display modes on a page that contains Web Parts controls.

  • A source file that contains the code for two custom WebPart controls that can be connected, and an interface.

  • A Web page that hosts all the controls.

  • An explanation of how the code example works.

The first part of the code example is the user control for changing display modes. You can obtain the source code for the user control from the Example section of the WebPartManager class overview. For information about display modes and how the user control works, see Walkthrough: Changing Display Modes on a Web Parts Page.

The second part of the example is the source file with the custom controls and the interface. Notice that the IZipCode interface exposes one method, and that this method as implemented in the custom ZipCodeWebPart control serves as a callback method to enable ZipCodeWebPart to act as a provider in a connection scenario. The other control, WeatherWebPart, acts as the consumer control in a connection; it can consume the particular interface provided by ZipCodeWebPart. In a real application, WeatherWebPart could consume a personalized ZIP Code value from the provider, and then provide graphical weather information to users.

For the code example to run, you must compile this source code. You can compile it explicitly and put the resulting assembly in your Web site's Bin folder or the global assembly cache. Alternatively, you can put the source code in your site's App_Code folder, where it will be dynamically compiled at run time. This code example uses dynamic compilation; therefore, notice that the Register directive for this component at the top of the Web page contains only TagPrefix and Namespace attributes, without an Assembly attribute. For a walkthrough that demonstrates how to compile, see Walkthrough: Developing and Using a Custom Web Server Control.

namespace Samples.AspNet.CS.Controls
  using System;
  using System.Web;
  using System.Web.Security;
  using System.Security.Permissions;
  using System.Web.UI;
  using System.Web.UI.WebControls;
  using System.Web.UI.WebControls.WebParts;

    Level = AspNetHostingPermissionLevel.Minimal)]
    Level = AspNetHostingPermissionLevel.Minimal)]
  public interface IZipCode
    string ZipCode { get; set;}

    Level = AspNetHostingPermissionLevel.Minimal)]
    Level = AspNetHostingPermissionLevel.Minimal)]
  public class ZipCodeWebPart : WebPart, IZipCode
    string zipCodeText = String.Empty;
    TextBox input;
    Button send;

    public ZipCodeWebPart()

    // Make the implemented property personalizable to save  
    // the Zip Code between browser sessions.
    public virtual string ZipCode
      get { return zipCodeText; }
      set { zipCodeText = value; }

    // This is the callback method that returns the provider.
    [ConnectionProvider("Zip Code", "ZipCodeProvider")]
    public IZipCode ProvideIZipCode()
      return this;

    protected override void CreateChildControls()
      input = new TextBox();
      send = new Button();
      send.Text = "Enter 5-digit Zip Code";
      send.Click += new EventHandler(this.submit_Click);

    private void submit_Click(object sender, EventArgs e)
      if (input.Text != String.Empty)
        zipCodeText = Page.Server.HtmlEncode(input.Text);
        input.Text = String.Empty;


    Level = AspNetHostingPermissionLevel.Minimal)]
    Level = AspNetHostingPermissionLevel.Minimal)]
  public class WeatherWebPart : WebPart
    private IZipCode _provider;
    string _zipSearch;
    Label DisplayContent;

    // This method is identified by the ConnectionConsumer  
    // attribute, and is the mechanism for connecting with  
    // the provider. 
    [ConnectionConsumer("Zip Code", "ZipCodeConsumer")]
    public void GetIZipCode(IZipCode Provider)
      _provider = Provider;

    protected override void OnPreRender(EventArgs e)

      if (this._provider != null)
        _zipSearch = _provider.ZipCode.Trim();
        DisplayContent.Text = "My Zip Code is:  " + _zipSearch;

    protected override void CreateChildControls()
      DisplayContent = new Label();


The third part of the code example is the Web page. Notice that it contains two WebPartZone zones, with the first one containing the two custom WebPart controls. There is also a CatalogZone zone, which contains a standard Calendar control that users can add to the page. The <asp:connectionszone> element provides a connection UI for users to create connections between controls. In the Page_PreRender method, notice that it checks to see whether the personalization data has changed and, if so, updates the text of Label1.

<%@ Page Language="C#" %>
<%@ Register TagPrefix="uc1" 
    Src="~/displaymodemenucs.ascx" %>
<%@ Register TagPrefix="aspSample" 
    Namespace="Samples.AspNet.CS.Controls" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"  

<script runat="server">

  protected void Page_PreRender(object sender, EventArgs e)
    // Clear the label if it has a previously set value.
    Label1.Text = String.Empty;

    // Cast the WebPartManager to the IPersonalizable interface  
    // so that you can access the property.  
    IPersonalizable stateData = (IPersonalizable)mgr1;
    if (stateData.IsDirty)
      Label1.Text = "WebPartManager personalization data is dirty.";

  protected void Button1_Click(object sender, EventArgs e)
    ProviderConnectionPoint provPoint = 
    ConsumerConnectionPoint connPoint = 
    WebPartConnection conn1 = mgr1.ConnectWebParts(zip1, provPoint,
      weather1, connPoint);

<html xmlns="" >
<head runat="server">
    <title>Untitled Page</title>
    <form id="form1" runat="server">
      <asp:WebPartManager ID="mgr1" runat="server" />
      <uc1:DisplayModeMenuCS ID="menu1" runat="server" />
      <asp:WebPartZone ID="WebPartZone1" runat="server">
          <aspSample:ZipCodeWebPart ID="zip1" runat="server"
            Title="Zip Code Provider" />
          <aspSample:WeatherWebPart ID="weather1" runat="server" 
            Title="Zip Code Consumer" />
      <asp:WebPartZone ID="WebPartZone2" runat="server">
      <asp:CatalogZone ID="CatalogZone1" runat="server">
          <asp:DeclarativeCatalogPart ID="DeclarativeCatalogPart1" 
              <asp:Calendar ID="Calendar1" runat="server" 
                Title="My Calendar" />
          <asp:PageCatalogPart ID="PageCatalogPart1" runat="server" />
      <asp:ConnectionsZone ID="ConnectionsZone1" runat="server" />
      <asp:Button ID="Button1" runat="server" 
        Text="Connect WebPart Controls" 
        OnClick="Button1_Click" />
      <hr />
      <asp:Label ID="Label1" runat="server" 
        Font-Bold="true" />

After you load the page in a browser, try to create some of the scenarios listed in the Remarks section of this topic that will change the personalization data. As you make various changes, when a change involves one of the personalization scenarios tracked by the WebPartManager control, the text of the Label1 control is displayed to indicate that personalization data has changed. For example, you can:

  • Create a connection between controls by clicking the Connect WebPart Controls button.

  • Use the Display Mode drop-down list control to switch the page to catalog mode, and add the My Calendar control to the second WebPartZone zone.

  • Change the page back to browse mode, click on the verbs menu (shown with an arrow symbol in the title bar) for the My Calendar control, and select Close to close it and add it to the page catalog.

  • Return the page to catalog mode, and add the My Calendar control back to the page.

  • Use the Display Mode control to switch the page to design mode, and rearrange the layout of the controls by dragging one or more of them to another zone, or to a different position in the same zone.

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