-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathServerControl1.cs
384 lines (344 loc) · 11.5 KB
/
ServerControl1.cs
1
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace webControlTest
{
[DefaultProperty("Text")]
[ToolboxData("<{0}:ServerControl1 runat=server></{0}:ServerControl1>")]
public class ServerControl1 : WebControl
{
// public const string webControl = "2a8b9574-6620-4df2-a36d-e8012bf624ba";
private Button submitButton;
private TextBox nameTextbox;
private Label namelbl;
private TextBox emailTextbox;
private Label emaillbl;
private RequiredFieldValidator emailValidator;
private RequiredFieldValidator nameValidator;
private RegularExpressionValidator emailEV;
private Label phonelbl;
private TextBox phoneTextbox;
private RegularExpressionValidator phoneEV;
private static readonly object EventSubmitKey = new object();
//private string imageheight = "100";
[Bindable(true)]
[Category("Appearance")]
[DefaultValue("")]
[Description("The text to display on the button")]
public string ButtonText
{
get
{
EnsureChildControls();
return submitButton.Text;
}
set
{
EnsureChildControls();
submitButton.Text = value;
}
}
[Bindable(true)]
[Category("Default")]
[DefaultValue("")]
[Description("The user name.")]
public string name
{
get
{
EnsureChildControls();
return nameTextbox.Text;
}
set
{
EnsureChildControls();
nameTextbox.Text = value;
}
}
[Bindable(true)]
[Category("Appearance")]
[DefaultValue("*")]
[Description("Error massage for the name validator.")]
public string NameErrorMessage
{
get
{
EnsureChildControls();
return nameValidator.ErrorMessage;
}
set
{
EnsureChildControls();
nameValidator.ErrorMessage = value;
nameValidator.ToolTip = value;
}
}
[Bindable(true)]
[Category("Appearance")]
[DefaultValue("")]
[Description("The text for the name label.")]
public string NameLabelText
{
get
{
EnsureChildControls();
return namelbl.Text;
}
set
{
EnsureChildControls();
namelbl.Text = value;
}
}
[Bindable(true)]
[Category("Default")]
[DefaultValue("")]
[Description("The e-mail address.")]
public string Email
{
get
{
EnsureChildControls();
return emailTextbox.Text;
}
set
{
EnsureChildControls();
emailTextbox.Text = value;
}
}
[Bindable(true)]
[Category("Appearance")]
[DefaultValue("格式不符合要求!")]
[Description("Error message for e-mail validator.")]
public string EmailEVMessage
{
get
{
EnsureChildControls();
return emailValidator.ErrorMessage;
}
set
{
EnsureChildControls();
emailEV.ErrorMessage = value;
emailEV.ToolTip = value;
}
}
[Bindable(true)]
[Category("Appearance")]
[DefaultValue("")]
[Description("Error message for e-mail validator.")]
public string EmailErrorMessage
{
get
{
EnsureChildControls();
return emailValidator.ErrorMessage;
}
set
{
EnsureChildControls();
emailValidator.ErrorMessage = value;
emailValidator.ToolTip = value;
}
}
[Bindable(true)]
[Category("Appearance")]
[DefaultValue("")]
[Description("The text for the e-mail label.")]
public string EmailLabelText
{
get
{
EnsureChildControls();
return emaillbl.Text;
}
set
{
EnsureChildControls();
emaillbl.Text = value;
}
}
[Bindable(true)]
[Category("Appearance")]
[DefaultValue("phone number:")]
[Description("The text for the e-mail label.")]
public string phoneLabelText
{
get
{
EnsureChildControls();
return phonelbl.Text;
}
set
{
EnsureChildControls();
phonelbl.Text = value;
}
}
[Bindable(true)]
[Category("Appearance")]
[DefaultValue("Format error.")]
[Description("Error message for e-mail validator.")]
public string phoneErrorMessage
{
get
{
EnsureChildControls();
return phoneEV.ErrorMessage;
}
set
{
EnsureChildControls();
phoneEV.ErrorMessage = value;
phoneEV.ToolTip = value;
}
}
// The Submit event
[Category("Action")]
[Description("Raised when the user clicks the button.")]
public event EventHandler Sumbit
{
add
{
Events.AddHandler(EventSubmitKey, value);
}
remove
{
Events.RemoveHandler(EventSubmitKey, value);
}
}
// The method that raises the Submit event
protected virtual void OnSubmit(EventArgs e)
{
EventHandler SubmitHandler = (EventHandler)Events[EventSubmitKey];
if (null != SubmitHandler)
{
SubmitHandler(this,e);
}
}
// Handler the Click event of the Button and raises the Submit event
private void _button_Click(object source, EventArgs e)
{
OnSubmit(EventArgs.Empty);
}
//protected override void RecreateChildControls()
//{
// // base.RecreateChildControls();
// EnsureChildControls();
//}
protected override void CreateChildControls()
{
//Control.Clear();
namelbl = new Label();
nameTextbox = new TextBox();
nameTextbox.ID = "nameTextBox";
nameValidator = new RequiredFieldValidator();
nameValidator.ID = "validator";
nameValidator.ControlToValidate = nameTextbox.ID;
nameValidator.Text = "Failed validation";
nameValidator.Display = ValidatorDisplay.Static;
emaillbl = new Label();
emailTextbox = new TextBox();
emailTextbox.ID = "emailTextBox";
emailValidator = new RequiredFieldValidator();
emailValidator.ID = "validator2";
emailValidator.ControlToValidate = emailTextbox.ID;
emailValidator.Text = "Failed validation.";
emailValidator.Display = ValidatorDisplay.Dynamic;
emailEV = new RegularExpressionValidator();
emailEV.ID = "validator3";
emailEV.ValidationExpression = @"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*";
emailEV.ControlToValidate = emailTextbox.ID;
emailEV.Text = "Format error.";
emailEV.Display = ValidatorDisplay.Dynamic;
phonelbl = new Label();
phoneTextbox = new TextBox();
phoneTextbox.ID = "phoneTextBox";
phoneEV = new RegularExpressionValidator();
phoneEV.ID = "validator4";
phoneEV.ValidationExpression = @"^1[0-9]{10}$";
phoneEV.ControlToValidate = phoneTextbox.ID;
phoneEV.Text = "Format error.";
// phoneEV.BackColor =
phoneEV.Display = ValidatorDisplay.Dynamic;
submitButton = new Button();
submitButton.ID = "button";
submitButton.Width = 100;
submitButton.Click += new EventHandler(_button_Click);
this.Controls.Add(namelbl);
this.Controls.Add(nameTextbox);
this.Controls.Add(nameValidator);
this.Controls.Add(emaillbl);
this.Controls.Add(emailTextbox);
this.Controls.Add(emailValidator);
this.Controls.Add(emailEV);
this.Controls.Add(submitButton);
this.Controls.Add(phonelbl);
this.Controls.Add(phoneTextbox);
this.Controls.Add(phoneEV);
}
protected override void Render(HtmlTextWriter writer)
{
// base.Render(writer);
AddAttributesToRender(writer);
writer.AddAttribute(HtmlTextWriterAttribute.Cellpadding, "1", false);
writer.RenderBeginTag(HtmlTextWriterTag.Table);
writer.RenderBeginTag(HtmlTextWriterTag.Tr);
writer.RenderBeginTag(HtmlTextWriterTag.Td);
namelbl.RenderControl(writer);
writer.RenderEndTag();
writer.RenderBeginTag(HtmlTextWriterTag.Td);
nameTextbox.RenderControl(writer);
writer.RenderEndTag();
writer.RenderBeginTag(HtmlTextWriterTag.Td);
nameValidator.RenderControl(writer);
writer.RenderEndTag();
writer.RenderEndTag();
writer.RenderBeginTag(HtmlTextWriterTag.Tr);
writer.RenderBeginTag(HtmlTextWriterTag.Td);
emaillbl.RenderControl(writer);
writer.RenderEndTag();
writer.RenderBeginTag(HtmlTextWriterTag.Td);
emailTextbox.RenderControl(writer);
writer.RenderEndTag();
writer.RenderBeginTag(HtmlTextWriterTag.Td);
emailValidator.RenderControl(writer);
emailEV.RenderControl(writer);
writer.RenderEndTag();
writer.RenderEndTag();
writer.RenderBeginTag(HtmlTextWriterTag.Tr);
writer.RenderBeginTag(HtmlTextWriterTag.Td);
phonelbl.RenderControl(writer);
writer.RenderEndTag();
writer.RenderBeginTag(HtmlTextWriterTag.Td);
phoneTextbox.RenderControl(writer);
writer.RenderEndTag();
writer.RenderBeginTag(HtmlTextWriterTag.Td);
phoneEV.RenderControl(writer);
writer.RenderEndTag();
writer.RenderEndTag();
writer.RenderBeginTag(HtmlTextWriterTag.Tr);
writer.AddAttribute(HtmlTextWriterAttribute.Colspan, "2", false);
writer.AddAttribute(HtmlTextWriterAttribute.Align, "right", false);
writer.RenderBeginTag(HtmlTextWriterTag.Td);
submitButton.RenderControl(writer);
writer.RenderEndTag();
writer.RenderBeginTag(HtmlTextWriterTag.Td);
writer.Write(" ");
writer.RenderEndTag();
writer.RenderEndTag();
writer.RenderEndTag();
}
//protected override void RenderContents(HtmlTextWriter output)
//{
// output.Write(Text);
//}
}
}