IPostBackEventHandler 事件实现

 1  [DefaultProperty("Text")]
 2     [ToolboxData("<{0}:HBButton2 runat=server></{0}:HBButton2>")]
 3     public class HBButton2: Control, IPostBackEventHandler
 4     {
 5         // 声明Click事件委托
 6         private static readonly object ClickKey = new object();
 7 
 8         public event EventHandler Click
 9         {
10             add
11             {
12                 Events.AddHandler(ClickKey, value);
13             }
14             remove
15             {
16                 Events.RemoveHandler(ClickKey, value);
17             }
18         }
19 
20         // 定义OnClick事件处理程序
21         protected virtual void OnClick(EventArgs e)
22         {
23             EventHandler clickEventDelegate =
24                (EventHandler)Events[ClickKey];
25             if (clickEventDelegate != null)
26             {
27                 clickEventDelegate(this, e);
28             }
29         }
30 
31         // 实现RaisePostBackEvent方法,处理回发事件
32         public void RaisePostBackEvent(string eventArgument)
33         {
34             OnClick(new EventArgs());
35         }
36 
37         protected override void Render(HtmlTextWriter output)
38         {
39             output.Write("<INPUT TYPE=submit name=" + this.UniqueID +
40                " Value='确定' />");
41         }
42 
43     }
posted @ 2007-05-23 15:44  herobeast  阅读(452)  评论(0编辑  收藏  举报