让Timer出现在Component Tray上。
代码
1using System;
2using System.ComponentModel;
3using System.Web.UI;
4using System.Web.UI.HtmlControls;
5
6namespace PowerAsp.NET.Comtrols
7{
8 /**//// <summary>
9 ///
10 /// </summary>
11 public class WebTimer2:Component
12 {
13 public WebTimer2()
14 {
15 }
16
17 private int _interval = 5000;
18 private bool _enable = false,_isHooked = false;
19 private WebTimer _timerControl = null;
20 private Page _page = null;
21
22 [DefaultValue(null)]
23 public Page _Page
24 {
25 get
26 {
27 return _page;
28 }
29 set
30 {
31 _page = value;
32 }
33 }
34 [
35 CategoryAttribute("Layout"),
36 DefaultValueAttribute(5000),
37 BindableAttribute(false),
38 DescriptionAttribute("")
39 ]
40 public int Interval
41 {
42 get
43 {
44 return _interval;
45 }
46 set
47 {
48 _interval = value;
49 }
50
51 }
52 [
53 CategoryAttribute("Layout"),
54 DefaultValueAttribute(false),
55 BindableAttribute(false),
56 DescriptionAttribute("")
57 ]
58 public bool Enabled
59 {
60 get
61 {
62 return _enable;
63 }
64 set
65 {
66 _enable = value;
67 if(_enable && !_isHooked)
68 HookPageLoad();
69 }
70 }
71 [CategoryAttribute("Action")]
72 public event EventHandler Timer
73 {
74 add
75 {
76 if(_timerControl == null)
77 _timerControl = new WebTimer();
78 _timerControl.Timer += value;
79 }
80 remove
81 {
82 if(_timerControl != null )
83 {
84 _timerControl.Timer -= value;
85 }
86 }
87 }
88 private void HookedPageLoad(object sender,EventArgs args)
89 {
90 if(_timerControl == null)
91 _timerControl = new WebTimer();
92 _timerControl.Interval = _interval;
93 _timerControl.Enabled = _enable;
94 if(_enable && _page != null)
95 {
96 foreach(Control c in _page.Controls)
97 {
98 if(c is HtmlForm)
99 {
100 c.Controls.Add(_timerControl);
101 }
102 }
103 }
104
105 }
106 private void HookPageLoad()
107 {
108 if(_page != null)
109 {
110 _page.Load += new EventHandler(HookedPageLoad);
111 _isHooked = true;
112 }
113 }
114 }
115}
116Wrapper WebTimer模式
1using System;
2using System.ComponentModel;
3using System.Web.UI;
4using System.Web.UI.HtmlControls;
5
6namespace PowerAsp.NET.Comtrols
7{
8 /**//// <summary>
9 ///
10 /// </summary>
11 public class WebTimer2:Component
12 {
13 public WebTimer2()
14 {
15 }
16
17 private int _interval = 5000;
18 private bool _enable = false,_isHooked = false;
19 private WebTimer _timerControl = null;
20 private Page _page = null;
21
22 [DefaultValue(null)]
23 public Page _Page
24 {
25 get
26 {
27 return _page;
28 }
29 set
30 {
31 _page = value;
32 }
33 }
34 [
35 CategoryAttribute("Layout"),
36 DefaultValueAttribute(5000),
37 BindableAttribute(false),
38 DescriptionAttribute("")
39 ]
40 public int Interval
41 {
42 get
43 {
44 return _interval;
45 }
46 set
47 {
48 _interval = value;
49 }
50
51 }
52 [
53 CategoryAttribute("Layout"),
54 DefaultValueAttribute(false),
55 BindableAttribute(false),
56 DescriptionAttribute("")
57 ]
58 public bool Enabled
59 {
60 get
61 {
62 return _enable;
63 }
64 set
65 {
66 _enable = value;
67 if(_enable && !_isHooked)
68 HookPageLoad();
69 }
70 }
71 [CategoryAttribute("Action")]
72 public event EventHandler Timer
73 {
74 add
75 {
76 if(_timerControl == null)
77 _timerControl = new WebTimer();
78 _timerControl.Timer += value;
79 }
80 remove
81 {
82 if(_timerControl != null )
83 {
84 _timerControl.Timer -= value;
85 }
86 }
87 }
88 private void HookedPageLoad(object sender,EventArgs args)
89 {
90 if(_timerControl == null)
91 _timerControl = new WebTimer();
92 _timerControl.Interval = _interval;
93 _timerControl.Enabled = _enable;
94 if(_enable && _page != null)
95 {
96 foreach(Control c in _page.Controls)
97 {
98 if(c is HtmlForm)
99 {
100 c.Controls.Add(_timerControl);
101 }
102 }
103 }
104
105 }
106 private void HookPageLoad()
107 {
108 if(_page != null)
109 {
110 _page.Load += new EventHandler(HookedPageLoad);
111 _isHooked = true;
112 }
113 }
114 }
115}
116Wrapper WebTimer模式