好的。我假设您已经创建了一个可视化 webpart,并且您的代码是这样添加到 webpart 类中的。
[ToolboxItemAttribute(false)]
public class addCustomToolPart : WebPart
{
private bool _intNumberofAnnouncement=10;
[WebBrowsable(true),
WebDisplayName("Number of announcement to display"),
WebDescription("Controls number of announcement"),
Category("Content Control"),
Personalizable(PersonalizationScope.Shared)]
public int NumberofAnnouncement { get { return _intNumberofAnnouncement; } set { _intNumberofAnnouncement = value; } }
protected override void CreateChildControls()
{
webpartusercontrolclass control = (webpartusercontrolclass)Page.LoadControl(_ascxPath);
control.addCustomToolPart = this;
Controls.Add(control);
}
}
现在在 UserControl 类中添加以下代码
public partial class webpartusercontrolclass : UserControl
{
public wpCustomToolPart addCustomToolPart { get; set; }
public int intNumberofAnnouncement { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
this.intNumberofAnnouncement = addCustomToolPart.NumberofAnnouncement;
}
}
numberofannouncements 的默认值为 10。并且可以通过编辑 webpart 属性进行更新。希望对你有帮助