BaseValidator.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /**
  2. * Namespace: System.Web.UI.WebControls
  3. * Class: BaseValidator
  4. *
  5. * Author: Gaurav Vaish
  6. * Contact: <[email protected]>, <[email protected]>
  7. * Status: 20%
  8. *
  9. * (C) Gaurav Vaish (2001)
  10. */
  11. using System;
  12. using System.Web;
  13. using System.Web.UI;
  14. using System.Drawing;
  15. namespace System.Web.UI.WebControls
  16. {
  17. public abstract class BaseValidator: Label, IValidator
  18. {
  19. //
  20. private PropertyDescriptor pDesc;
  21. private string ctValid = String.Empty;
  22. private ValidatorDisplay vDisp = ValidatorDisplay.Static;
  23. private bool enableClientScript; //TODO: check the default value := false;
  24. private bool enabled = true;
  25. private string errorMessage = String.Empty;
  26. private Color foreColor = Color.Red;
  27. private bool isValid = true;
  28. private bool propertiesValid;
  29. private bool renderUplevel;
  30. public static PropertyDescriptor GetValidationProperty(object component)
  31. {
  32. //TODO: Have to workout this one!
  33. return null;
  34. }
  35. public string ControlToValidate
  36. {
  37. get
  38. {
  39. return ctValid;
  40. }
  41. set
  42. {
  43. ctValid = value;
  44. }
  45. }
  46. public ValidatorDisplay Display
  47. {
  48. get
  49. {
  50. return vDisp;
  51. }
  52. set
  53. {
  54. //TODO: Throw new exception ArgumentException("....") if the value is not valid
  55. vDisp = value;
  56. }
  57. }
  58. public bool EnableClientScript
  59. {
  60. get
  61. {
  62. return enableClientScript;
  63. }
  64. set
  65. {
  66. enableClientScript = value;
  67. }
  68. }
  69. public override bool Enabled
  70. {
  71. get
  72. {
  73. return enabled;
  74. }
  75. set
  76. {
  77. enabled = value;
  78. }
  79. }
  80. public string ErrorMessage
  81. {
  82. get
  83. {
  84. return errorMessage;
  85. }
  86. set
  87. {
  88. errorMessage = value;
  89. }
  90. }
  91. public override Color ForeColor
  92. {
  93. get
  94. {
  95. return foreColor;
  96. }
  97. set
  98. {
  99. foreColor = value;
  100. }
  101. }
  102. public bool IsValid
  103. {
  104. get
  105. {
  106. return isValid;
  107. }
  108. set
  109. {
  110. isValid = value;
  111. }
  112. }
  113. public void Validate()
  114. {
  115. // TODO: write the validation code
  116. // TODO: update the value of isValid
  117. }
  118. protected BaseValidator()
  119. {
  120. // Dummy Constructor
  121. }
  122. protected bool PropertiesValid
  123. {
  124. get
  125. {
  126. // TODO: throw HttpException, but when? How do I know about all the controls?
  127. return propertiesValid;
  128. }
  129. }
  130. protected bool RenderUplevel
  131. {
  132. get
  133. {
  134. //TODO: To set the value of renderUplevel. Problem: when, how?
  135. return renderUplevel;
  136. }
  137. }
  138. protected void CheckControlValidationProperty(string name, string propertyName)
  139. {
  140. //TODO: I think it needs to be overridden. I may be wrong!
  141. //TODO: When to throw HttpException(...)
  142. }
  143. protected virtual bool ControlPropertiesValid()
  144. {
  145. // Do I need to do anything? But what?
  146. // What do I do with ControlToValidate?
  147. return true;
  148. }
  149. protected virtual bool DetermineRenderUplevel()
  150. {
  151. // From where?
  152. return true;
  153. }
  154. }
  155. }