在此自定义内容查询Web部件中,以下代码有效。我可以更改Web部件标题和ToolPart标题:
public class CustomWebPart1 : ContentByQueryWebPart
{
public override ToolPart[] GetToolParts()
{
ToolPart[] toolPartArray = base.GetToolParts();
return new ToolPart[] { new CustomContentQueryWebPartToolPart(), toolPartArray[0], toolPartArray[1] };
}
}
public class CustomContentQueryWebPartToolPart : ToolPart
{
TextBox txt1;
CustomWebPart1 wp;
public CustomContentQueryWebPartToolPart()
{
this.Title = "My Custom Properties";
}
protected override void CreateChildControls()
{
txt1 = new TextBox();
this.Controls.Add(txt1);
base.CreateChildControls();
}
public override void ApplyChanges()
{
this.Title = "ToolPart Title: " + txt1.Text;
wp = this.WebPartToEdit as CustomWebPart1;
wp.Title = "WebPart Title: " + txt1.Text;
base.ApplyChanges();
}
}
但是,如果我更改数组中的位置(这是Web部件属性的显示顺序),更改Web部件标题将不再起作用!
public override ToolPart[] GetToolParts()
{
ToolPart[] toolPartArray = base.GetToolParts();
return new ToolPart[] { toolPartArray[0], toolPartArray[1], new CustomContentQueryWebPartToolPart() };
}
这里有什么问题?这是一个错误吗?更改ToolPart标题仍然有效。