如何修改自定义Webpart的标题?(downmoon)
如何修改自定义Webpart的标题?
在事件里很好写
比如
private void BtnText_Click(object sender, EventArgs e)
{
this.Title = this.txtTitle.Text;
}
{
this.Title = this.txtTitle.Text;
}
另外网上比较浒的一个方法是:
public override ToolPart[] GetToolParts()
{
ToolPart[] toolparts = new ToolPart[2];
WebPartToolPart wptp = new WebPartToolPart();
CustomPropertyToolPart custom = new CustomPropertyToolPart();
toolparts[0] = wptp;
//hide the default title property
//wptp.Hide(Microsoft.SharePoint.WebPartPages.WebPartToolPart.Properties.Title);
toolparts[1] = custom;
return toolparts;
}
{
ToolPart[] toolparts = new ToolPart[2];
WebPartToolPart wptp = new WebPartToolPart();
CustomPropertyToolPart custom = new CustomPropertyToolPart();
toolparts[0] = wptp;
//hide the default title property
//wptp.Hide(Microsoft.SharePoint.WebPartPages.WebPartToolPart.Properties.Title);
toolparts[1] = custom;
return toolparts;
}
可是大多数时候由于页面中不上一个Webpart,,有时也会互相打架,导致无效!
其实下面的方法才是正解
protected override void OnInit(EventArgs e)
{
base.OnInit (e);
this.Title = "Set title here...";
}
新问题是:如何将一个HyperLink做WebPart的标题?
后来经过仔细研究,原来
WebPart有个属性可以赋值:
this.DetailLink=this.lblMoreUrl.Text;
OK!· 爽!