[英]Sharepoint 2013: How to add custom tool part
I have a web part containing a repeater control which display the announcements. 我有一个包含转发器控件的Web部件,该控件显示通知。 I want to make a custom tool part which enables a user to limit the number of rows of repeater.
我想制作一个自定义工具部件,使用户可以限制转发器的行数。 I have created a text box that takes the number of news to display as an input.
我创建了一个文本框,将要显示的新闻数量作为输入。 Now I am confused that how do I bind its event with the 'Ok' button ie when the button is pressed the code should render the input and make the repeater accordingly.
现在我很困惑,如何将其事件与“确定”按钮绑定,即当按下按钮时,代码应呈现输入并相应地使中继器。 Here is my code:
这是我的代码:
[WebBrowsable(true),
WebDisplayName("Number of announcement to display"),
WebDescription("Controls number of announcement"),
Category("Content Control"),
Personalizable(PersonalizationScope.Shared)]
public int NumberofAnnouncement
{
get;
set;
}
How do I bind the event ? 如何绑定事件? I need some assistance.
我需要一些帮助。
Ok. 好。 I'm assuming that you have created a visual webpart and your code is added like this in webpart class.
我假设您已经创建了一个可视化的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);
}
}
Now in the UserControl Class add below code 现在在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;
}
}
Default value for the numberofannouncements will be 10. And can be updated through edit webpart properties. 通告数量的默认值为10。可以通过编辑Webpart属性进行更新。 Hope this will help you
希望这个能对您有所帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.