Asp.net 如何在EditorPart中更新Zone和ZoneIndex
我创建了一个自定义的EditorPart,我想在ApplyChanges方法中将WebPart上的Zone和ZoneIndex设置为Edit。但是,这些特定属性是只读的,因此我无法设置它们。LayoutEditor包含这些属性,因此应该可以更新它们。如何在Web部件上设置区域和区域索引?我找到了方法。这是令人惊讶的简单Asp.net 如何在EditorPart中更新Zone和ZoneIndex,asp.net,web-parts,Asp.net,Web Parts,我创建了一个自定义的EditorPart,我想在ApplyChanges方法中将WebPart上的Zone和ZoneIndex设置为Edit。但是,这些特定属性是只读的,因此我无法设置它们。LayoutEditor包含这些属性,因此应该可以更新它们。如何在Web部件上设置区域和区域索引?我找到了方法。这是令人惊讶的简单 public override bool ApplyChanges() { // Set Zone and ZoneIndex here WebPartManager m
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;
}