Web Part Swap ASP.NET

Joined
Dec 29, 2008
Messages
2
Reaction score
0
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;
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top