奇怪,第一次发居然是斜体的。
控制数字类型输入
dll
source
1 using System;
2 using System.Web.UI;
3 using System.Web.UI.WebControls;
4 using System.ComponentModel;
5 using System.Collections;
6 using System.Text;
7
8 namespace ZPTControls
9 {
10 [DefaultProperty("Text"),
11 ToolboxData("<{0}:CustomNumericText runat=server>")]
12 public class CustomNumericText : Control,INamingContainer
13 {
14 // Methods
15 public CustomNumericText()
16 {
17 this.cur_id = "txtNum";
18 }
19
20
21 #region 注册JavaScript
22 private void RegisterJavascript()
23 {
24 StringBuilder sb = new StringBuilder("");
25 sb.Append(@"
26
213 "
214 );
215 Page.RegisterClientScriptBlock("CheckInput_exp", sb.ToString());
216 }
217 #endregion
218
219 #region 加载控件
220 private void contol_Load(object sender, EventArgs e)
221 {
222 RegisterJavascript();
223 object[] objArray1 = new object[11] { "javascript:CheckInput_exp(this,'", this.CheckType, "','", this.strErrorInfo, "',", this.MaxValue.ToString(), ",", this.MinValue.ToString(), ",", this.ZeroValue.ToString(), ");" } ;
224 ((TextBox) this.Controls[0]).Attributes["onBlur"] = string.Concat(objArray1);
225 ((TextBox) this.Controls[0]).MaxLength = this.MaxLength;
226 ((TextBox) this.Controls[0]).Width = (Unit) this.width;
227 ((TextBox) this.Controls[0]).TabIndex = this.TabIndex;
228 ((TextBox) this.Controls[0]).CssClass = this.CssClass;
229 }
230
231 #endregion
232
233 #region 重写CreateChildControls
234 protected override void CreateChildControls()
235 {
236 TextBox box1 = new TextBox();
237 box1.Enabled = true;
238 box1.Attributes["id"] = this.cur_id + box1.ClientID;
239 box1.EnableViewState = true;
240 box1.CssClass = "";
241 box1.AccessKey ="";
242 this.Controls.Add(box1);
243 base.PreRender += new EventHandler(this.contol_Load);
244 }
245 #endregion
246
247 #region 控件属性
248 // Properties
249 #region 数据类型
250 ///
251 /// 数据类型
252 ///
253 [Description("数据类型:"), DefaultValue(0)]
254 public CustomNumericText.DataType CheckType
255 {
256 get
257 {
258 return this.SetType;
259 }
260 set
261 {
262 this.SetType = value;
263 this.EnsureChildControls();
264 }
265 }
266 #endregion
267
268 #region 控件的已启用状态
269 ///
270 /// 控件的已启用状态
271 ///
272 [Description("控件的已启用状态"), DefaultValue(0)]
273 public bool Enabled
274 {
275 get
276 {
277 this.EnsureChildControls();
278 return ((TextBox) this.Controls[0]).Enabled;
279 }
280 set
281 {
282 this.EnsureChildControls();
283 ((TextBox) this.Controls[0]).Enabled = value;
284 }
285 }
286 #endregion
287
288 #region 控件的编程名称
289 ///
290 /// 编程名称
291 ///
292 [Description("控件的编程名称"), DefaultValue(0)]
293 public override string ID
294 {
295 get
296 {
297 return this.cur_id;
298 }
299 set
300 {
301 this.cur_id = value;
302 this.EnsureChildControls();
303 }
304 }
305 #endregion
306
307 #region 最大长度
308 ///
309 /// 最长长度
310 ///
311 [Description("最长长度"), DefaultValue(0)]
312 public int MaxLength
313 {
314 get
315 {
316 if (this.ViewState["maxLength"] == null)
317 {
318 return 8;
319 }
320 return (int) this.ViewState["maxLength"];
321 }
322 set
323 {
324 this.ViewState["maxLength"] = value;
325 }
326 }
327
328 #endregion
329
330 #region 最大值
331 ///
332 /// 最大值
333 ///
334 [Description("最大值"), DefaultValue(0)]
335 public decimal MaxValue
336 {
337 get
338 {
339 if (this.ViewState["MaxValue"] == null)
340 {
341 return new decimal(-1, -1, -1, false, 0);
342 }
343 return (decimal) this.ViewState["MaxValue"];
344 }
345 set
346 {
347 this.ViewState["MaxValue"] = value;
348 }
349 }
350
351 #endregion
352
353 #region 最小值
354 ///
355 /// 最小值
356 ///
357 [Description("最小值"), DefaultValue(0)]
358 public decimal MinValue
359 {
360 get
361 {
362 if (this.ViewState["MinValue"] == null)
363 {
364 return new decimal(-1,-1,-1,true,0);
365 }
366 return (decimal) this.ViewState["MinValue"];
367 }
368 set
369 {
370 this.ViewState["MinValue"] = value;
371 }
372 }
373
374 #endregion
375
376 #region 错误信息
377 ///
378 /// 自定义错误信息
379 ///
380 [Description("自定义错误信息"), DefaultValue(0)]
381 public string strErrorInfo
382 {
383 get
384 {
385 if (this.ViewState["strErrorInfo"] == null)
386 {
387 return "";
388 }
389 return this.ViewState["strErrorInfo"].ToString();
390 }
391 set
392 {
393 this.ViewState["strErrorInfo"] = value;
394 }
395 }
396
397 #endregion
398
399 #region Tab键顺序
400 [DefaultValue(0), Description("Tab键顺序")]
401 public short TabIndex
402 {
403 get
404 {
405 if (this.ViewState["TabIndex"] == null)
406 {
407 return 0;
408 }
409 return (short) this.ViewState["TabIndex"];
410 }
411 set
412 {
413 this.ViewState["TabIndex"] = value;
414 }
415 }
416 #endregion
417
418 #region css类名
419 ///
420 /// css类名
421 ///
422 [Description("css类名"), DefaultValue(0)]
423 public string CssClass
424 {
425 get
426 {
427 this.EnsureChildControls();
428 return ((TextBox) this.Controls[0]).CssClass;
429 }
430 set
431 {
432 this.EnsureChildControls();
433 ((TextBox) this.Controls[0]).CssClass = value;
434 }
435 }
436
437 #endregion
438
439 #region 文本值
440 [Description("文本值"), DefaultValue(0)]
441 public string Text
442 {
443 get
444 {
445 this.EnsureChildControls();
446 return ((TextBox) this.Controls[0]).Text;
447 }
448 set
449 {
450 this.EnsureChildControls();
451 ((TextBox) this.Controls[0]).Text = value;
452 }
453 }
454
455 #endregion
456
457 #region 宽度
458 [Description("宽度"), DefaultValue(0)]
459 public int width
460 {
461 get
462 {
463 if (this.ViewState["width"] == null)
464 {
465 return 100;
466 }
467 return (int) this.ViewState["width"];
468 }
469 set
470 {
471 this.ViewState["width"] = value;
472 }
473 }
474
475 #endregion
476
477 #region 空值默认
478 [Description("空值默认"), DefaultValue(0)]
479 public decimal ZeroValue
480 {
481 get
482 {
483 if (this.ViewState["ZeroValue"] == null)
484 {
485 return new decimal(0);
486 }
487 return Math.Abs((decimal) this.ViewState["ZeroValue"]);
488 }
489 set
490 {
491 this.ViewState["ZeroValue"] = Math.Abs(value);
492 }
493 }
494
495 #endregion
496 #endregion
497
498 // Fields
499 private string cur_id;
500 private DataType SetType;
501
502 // Nested Types
503 public enum DataType
504 {
505 // Fields
506 PositiveFloat = 5,
507 Price = 2,
508 Integer = 1,
509 Quantity = 0,
510 RebateRate = 3,
511 TaxRate = 4
512 }
513 }
514 }
515
2 using System.Web.UI;
3 using System.Web.UI.WebControls;
4 using System.ComponentModel;
5 using System.Collections;
6 using System.Text;
7
8 namespace ZPTControls
9 {
10 [DefaultProperty("Text"),
11 ToolboxData("<{0}:CustomNumericText runat=server>")]
12 public class CustomNumericText : Control,INamingContainer
13 {
14 // Methods
15 public CustomNumericText()
16 {
17 this.cur_id = "txtNum";
18 }
19
20
21 #region 注册JavaScript
22 private void RegisterJavascript()
23 {
24 StringBuilder sb = new StringBuilder("");
25 sb.Append(@"
26
213 "
214 );
215 Page.RegisterClientScriptBlock("CheckInput_exp", sb.ToString());
216 }
217 #endregion
218
219 #region 加载控件
220 private void contol_Load(object sender, EventArgs e)
221 {
222 RegisterJavascript();
223 object[] objArray1 = new object[11] { "javascript:CheckInput_exp(this,'", this.CheckType, "','", this.strErrorInfo, "',", this.MaxValue.ToString(), ",", this.MinValue.ToString(), ",", this.ZeroValue.ToString(), ");" } ;
224 ((TextBox) this.Controls[0]).Attributes["onBlur"] = string.Concat(objArray1);
225 ((TextBox) this.Controls[0]).MaxLength = this.MaxLength;
226 ((TextBox) this.Controls[0]).Width = (Unit) this.width;
227 ((TextBox) this.Controls[0]).TabIndex = this.TabIndex;
228 ((TextBox) this.Controls[0]).CssClass = this.CssClass;
229 }
230
231 #endregion
232
233 #region 重写CreateChildControls
234 protected override void CreateChildControls()
235 {
236 TextBox box1 = new TextBox();
237 box1.Enabled = true;
238 box1.Attributes["id"] = this.cur_id + box1.ClientID;
239 box1.EnableViewState = true;
240 box1.CssClass = "";
241 box1.AccessKey ="";
242 this.Controls.Add(box1);
243 base.PreRender += new EventHandler(this.contol_Load);
244 }
245 #endregion
246
247 #region 控件属性
248 // Properties
249 #region 数据类型
250 ///
251 /// 数据类型
252 ///
253 [Description("数据类型:"), DefaultValue(0)]
254 public CustomNumericText.DataType CheckType
255 {
256 get
257 {
258 return this.SetType;
259 }
260 set
261 {
262 this.SetType = value;
263 this.EnsureChildControls();
264 }
265 }
266 #endregion
267
268 #region 控件的已启用状态
269 ///
270 /// 控件的已启用状态
271 ///
272 [Description("控件的已启用状态"), DefaultValue(0)]
273 public bool Enabled
274 {
275 get
276 {
277 this.EnsureChildControls();
278 return ((TextBox) this.Controls[0]).Enabled;
279 }
280 set
281 {
282 this.EnsureChildControls();
283 ((TextBox) this.Controls[0]).Enabled = value;
284 }
285 }
286 #endregion
287
288 #region 控件的编程名称
289 ///
290 /// 编程名称
291 ///
292 [Description("控件的编程名称"), DefaultValue(0)]
293 public override string ID
294 {
295 get
296 {
297 return this.cur_id;
298 }
299 set
300 {
301 this.cur_id = value;
302 this.EnsureChildControls();
303 }
304 }
305 #endregion
306
307 #region 最大长度
308 ///
309 /// 最长长度
310 ///
311 [Description("最长长度"), DefaultValue(0)]
312 public int MaxLength
313 {
314 get
315 {
316 if (this.ViewState["maxLength"] == null)
317 {
318 return 8;
319 }
320 return (int) this.ViewState["maxLength"];
321 }
322 set
323 {
324 this.ViewState["maxLength"] = value;
325 }
326 }
327
328 #endregion
329
330 #region 最大值
331 ///
332 /// 最大值
333 ///
334 [Description("最大值"), DefaultValue(0)]
335 public decimal MaxValue
336 {
337 get
338 {
339 if (this.ViewState["MaxValue"] == null)
340 {
341 return new decimal(-1, -1, -1, false, 0);
342 }
343 return (decimal) this.ViewState["MaxValue"];
344 }
345 set
346 {
347 this.ViewState["MaxValue"] = value;
348 }
349 }
350
351 #endregion
352
353 #region 最小值
354 ///
355 /// 最小值
356 ///
357 [Description("最小值"), DefaultValue(0)]
358 public decimal MinValue
359 {
360 get
361 {
362 if (this.ViewState["MinValue"] == null)
363 {
364 return new decimal(-1,-1,-1,true,0);
365 }
366 return (decimal) this.ViewState["MinValue"];
367 }
368 set
369 {
370 this.ViewState["MinValue"] = value;
371 }
372 }
373
374 #endregion
375
376 #region 错误信息
377 ///
378 /// 自定义错误信息
379 ///
380 [Description("自定义错误信息"), DefaultValue(0)]
381 public string strErrorInfo
382 {
383 get
384 {
385 if (this.ViewState["strErrorInfo"] == null)
386 {
387 return "";
388 }
389 return this.ViewState["strErrorInfo"].ToString();
390 }
391 set
392 {
393 this.ViewState["strErrorInfo"] = value;
394 }
395 }
396
397 #endregion
398
399 #region Tab键顺序
400 [DefaultValue(0), Description("Tab键顺序")]
401 public short TabIndex
402 {
403 get
404 {
405 if (this.ViewState["TabIndex"] == null)
406 {
407 return 0;
408 }
409 return (short) this.ViewState["TabIndex"];
410 }
411 set
412 {
413 this.ViewState["TabIndex"] = value;
414 }
415 }
416 #endregion
417
418 #region css类名
419 ///
420 /// css类名
421 ///
422 [Description("css类名"), DefaultValue(0)]
423 public string CssClass
424 {
425 get
426 {
427 this.EnsureChildControls();
428 return ((TextBox) this.Controls[0]).CssClass;
429 }
430 set
431 {
432 this.EnsureChildControls();
433 ((TextBox) this.Controls[0]).CssClass = value;
434 }
435 }
436
437 #endregion
438
439 #region 文本值
440 [Description("文本值"), DefaultValue(0)]
441 public string Text
442 {
443 get
444 {
445 this.EnsureChildControls();
446 return ((TextBox) this.Controls[0]).Text;
447 }
448 set
449 {
450 this.EnsureChildControls();
451 ((TextBox) this.Controls[0]).Text = value;
452 }
453 }
454
455 #endregion
456
457 #region 宽度
458 [Description("宽度"), DefaultValue(0)]
459 public int width
460 {
461 get
462 {
463 if (this.ViewState["width"] == null)
464 {
465 return 100;
466 }
467 return (int) this.ViewState["width"];
468 }
469 set
470 {
471 this.ViewState["width"] = value;
472 }
473 }
474
475 #endregion
476
477 #region 空值默认
478 [Description("空值默认"), DefaultValue(0)]
479 public decimal ZeroValue
480 {
481 get
482 {
483 if (this.ViewState["ZeroValue"] == null)
484 {
485 return new decimal(0);
486 }
487 return Math.Abs((decimal) this.ViewState["ZeroValue"]);
488 }
489 set
490 {
491 this.ViewState["ZeroValue"] = Math.Abs(value);
492 }
493 }
494
495 #endregion
496 #endregion
497
498 // Fields
499 private string cur_id;
500 private DataType SetType;
501
502 // Nested Types
503 public enum DataType
504 {
505 // Fields
506 PositiveFloat = 5,
507 Price = 2,
508 Integer = 1,
509 Quantity = 0,
510 RebateRate = 3,
511 TaxRate = 4
512 }
513 }
514 }
515

