views:

36

answers:

1

I created a custom EditorPart, and I want to set the Zone and ZoneIndex on the WebPartToEdit in the ApplyChanges method. However, these particular properties are read-only, so I can't set them. The LayoutEditor contains these properties, so it should be possible to update them. How can I set the Zone and ZoneIndex on a WebPart?

A: 

I figured out how to do it. It was surprisingly simple.

public override bool ApplyChanges()
{
  // Set Zone and ZoneIndex here
  WebPartManager manager = WebPartManager.GetCurrentWebPartManager(Page);
  WebPartZone selectedZone = null;

  // Find the selected zone
  foreach (WebPartZone zone in manager.Zones)
  {
    if (zone.DisplayTitle == Zones.SelectedValue)
    {
      selectedZone = zone;
      break;
    }
  }

  // Get the index
  int selectedIndex = 0;
  int.TryParse(ZoneIndex.Text, out selectedIndex);

  // Move the web part
  if (selectedZone != null)
  {
     manager.MoveWebPart(WebPartToEdit, selectedZone, selectedIndex);
  }

  return true;
}
Rachel Martin