【IT168技术文档】
[Guid("288802c4-4dfe-45b6-bb28-49dda89ec225")] public class MyWebPartVerb:WebPart { //通过重载这个属性可以添加自定义的Verbs. public override WebPartVerbCollection Verbs { get { //这是一个触发JavaScript事件的WebPart. WebPartVerb objFirst = new WebPartVerb("FirstVerbId","alert('XXXXXXX!');"); objFirst.Text = "first verb text"; objFirst.Description = "first verb description"; objFirst.ImageUrl = "_layouts/images/loisandclark/favicon.gif"; //这是一个触发Server端事件的WebPart. WebPartVerb objSecond = new WebPartVerb("SecondVerbId",new WebPartEventHandler(SecondVerbHandler)); objSecond.Text = "second verb text"; objSecond.Description = "second verb description"; WebPartVerb[] objVerbs = new WebPartVerb[] {objFirst, objSecond}; //在这里,我们保留原有的Verbs. WebPartVerbCollection objVerbCollection = new WebPartVerbCollection(base.Verbs, objVerbs); return objVerbCollection; } } protected void SecondVerbHandler(object sender, WebPartEventArgs args) { //Do something... } }