比较简单,不写注释了
CS代码如下
1
using System;
2
using System.Collections.Generic;
3
using System.ComponentModel;
4
using System.Text;
5
using System.Web;
6
using System.Web.UI;
7
using System.Web.UI.WebControls;
8
using System.Security.Permissions;
9
10
[assembly: WebResource("WYN.WebControls.script_PopupCalender.js", "application/x-javascript", PerformSubstitution = true)]
11
[assembly:TagPrefix("WYN","TextBoxCalendar")]
12
namespace WYN.WebControls
13
{
14
[ToolboxData("<{0}:TextBoxCalendar runat=server></{0}:TextBoxCalendar>")]
15
[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")]
16
public class TextBoxCalendar :TextBox
17
{
18
19
[Bindable(true)]
20
[Category("Appearance")]
21
[DefaultValue("")]
22
[Localizable(true)]
23
[Description("控件选定的短日期字符串格式")]
24
public string ShortDate
25
{
26
get
27
{
28
if (String.IsNullOrEmpty(Text))
29
base.Text = System.DateTime.Now.Date.ToShortDateString();
30
31
return base.Text;
32
}
33
34
set
35
{
36
base.Text = value;
37
}
38
}
39
40
[Bindable(true)]
41
[Category("Appearance")]
42
[DefaultValue("")]
43
[Localizable(true)]
44
[Description("控件选定的日期")]
45
public DateTime SelectedDate
46
{
47
get
48
{
49
if (String.IsNullOrEmpty(Text))
50
base.Text = System.DateTime.Now.Date.ToShortDateString();
51
52
return Convert.ToDateTime(base.Text);
53
}
54
set
55
{
56
base.Text = value.ToShortDateString();
57
}
58
}
59
60
[Browsable(false)]
61
public override string Text
62
{
63
get
64
{
65
return base.Text;
66
}
67
set
68
{
69
;
70
}
71
}
72
73
[Browsable(false)]
74
public override TextBoxMode TextMode
75
{
76
get
77
{
78
return base.TextMode;
79
}
80
set
81
{
82
;
83
}
84
}
85
86
[Browsable(false)]
87
public override bool ReadOnly
88
{
89
get
90
{
91
return true;
92
}
93
}
94
95
protected override void OnLoad(EventArgs e)
96
{
97
// Define the resource name and type.
98
String rsname = "WYN.WebControls.script_PopupCalender.js";
99
Type rstype = this.GetType();
100
101
// Get a ClientScriptManager reference from the Page class.
102
ClientScriptManager cs = Page.ClientScript;
103
104
// Register the client resource with the page.
105
cs.RegisterClientScriptResource(rstype, rsname);
106
107
108
base.OnLoad(e);
109
}
110
111
protected override void Render(HtmlTextWriter writer)
112
{
113
writer.AddAttribute(HtmlTextWriterAttribute.Onclick, "PopupCalender();");
114
base.Render(writer);
115
}
116
}
117
}
118

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

JS文件如下















































































































































































有一个地方要特别说明一下:
由于不想让使用者见到JavaScript文件,不想让他们手工设JS路径,所以代码用到了2.0里的一个新东西
在Namespace上打上如下Attribt
[assembly: WebResource("WYN.WebControls.script_PopupCalender.js", "application/x-javascript", PerformSubstitution = true)]
注册JS的方法如下:















然后在JS文件右击,选属性,生成操作(Build Action) 设为嵌入的资源
收工!可以用了