BaseValidator.cs 3.9 KB

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