I want to contribute this to someone who is searching for it:
This will make it so when you drag a web part over to another web part, they will be swapped.
private WebPart _webPartToSwap = null;
private WebZone _originalWebZone = null;
protected void Page_Load(object sender, EventArgs e)
{
WebPartDisplayMode displayMode = WebPartManager.SupportedDisplayModes[1];
WebPartManager.DisplayMode = displayMode;
}
protected void WebPartManager_WebPartMoved(object sender, WebPartEventArgs e)
{
//Make sure there is a web part we need to swap
if (_webPartToSwap != null)
{
WebPartManager.MoveWebPart(_webPartToSwap, (WebPartZoneBase)_originalWebZone, 0);
}
}
protected void WebPartManager_WebPartMoving(object sender, WebPartMovingEventArgs e)
{
//Clear the old web part being held in memory
if (_webPartToSwap != null)
{
_webPartToSwap = null;
}
//Clear the old web zone being held in memory
if (_originalWebZone != null)
{
_originalWebZone = null;
}
//Make sure that the zone the web part being moved to has at least one control
if (e.Zone.WebParts.Count > 0)
{
//Get a reference of the web part that we need to move to the location of the calling web part.
_webPartToSwap = e.Zone.WebParts[0];
_originalWebZone = e.WebPart.Zone;
}
}
This will make it so when you drag a web part over to another web part, they will be swapped.
private WebPart _webPartToSwap = null;
private WebZone _originalWebZone = null;
protected void Page_Load(object sender, EventArgs e)
{
WebPartDisplayMode displayMode = WebPartManager.SupportedDisplayModes[1];
WebPartManager.DisplayMode = displayMode;
}
protected void WebPartManager_WebPartMoved(object sender, WebPartEventArgs e)
{
//Make sure there is a web part we need to swap
if (_webPartToSwap != null)
{
WebPartManager.MoveWebPart(_webPartToSwap, (WebPartZoneBase)_originalWebZone, 0);
}
}
protected void WebPartManager_WebPartMoving(object sender, WebPartMovingEventArgs e)
{
//Clear the old web part being held in memory
if (_webPartToSwap != null)
{
_webPartToSwap = null;
}
//Clear the old web zone being held in memory
if (_originalWebZone != null)
{
_originalWebZone = null;
}
//Make sure that the zone the web part being moved to has at least one control
if (e.Zone.WebParts.Count > 0)
{
//Get a reference of the web part that we need to move to the location of the calling web part.
_webPartToSwap = e.Zone.WebParts[0];
_originalWebZone = e.WebPart.Zone;
}
}