WebPart,大家都不陌生了吧,下面我谈谈我在WebPart开发中的心得以及经验。
1.添加WebPart自定义动词
首先让你写的控件继承IWebPart接口,以及IWebActionable接口,当然还有System.Web.UI.UserControl
namespace
NetRoute.CMS.WebParts
... {
public partial class NewsList : System.Web.UI.UserControl, IWebPart, IWebActionable
...{
protected new void Page_Load(object sender, EventArgs e)
...{
base.Page_Load(sender, e);
}
}
... {
public partial class NewsList : System.Web.UI.UserControl, IWebPart, IWebActionable
...{
protected new void Page_Load(object sender, EventArgs e)
...{
base.Page_Load(sender, e);
}
}
然后在类里面写
IWebActionable 成员
#region IWebActionable 成员
WebPartVerbCollection IWebActionable.Verbs
...{
get
...{
List<WebPartVerb> menu = new List<WebPartVerb>();
WebPartVerb menuItem = new WebPartVerb("定制", new WebPartEventHandler(this.AddToCart));
menuItem.Text = "定制";
menuItem.Description = "编辑当前功能";
menu.Add(menuItem);
return new WebPartVerbCollection(menu);
}
}
public void AddToCart(object sender, WebPartEventArgs e)
...{
//点击你添加那个动词之后的实现效果
}
#endregion
WebPartVerbCollection IWebActionable.Verbs
...{
get
...{
List<WebPartVerb> menu = new List<WebPartVerb>();
WebPartVerb menuItem = new WebPartVerb("定制", new WebPartEventHandler(this.AddToCart));
menuItem.Text = "定制";
menuItem.Description = "编辑当前功能";
menu.Add(menuItem);
return new WebPartVerbCollection(menu);
}
}
public void AddToCart(object sender, WebPartEventArgs e)
...{
//点击你添加那个动词之后的实现效果
}
#endregion
把做好的用户控件拖入WebPartZone里面,在运行时,你就可以看见你所要添加的动词了。。。