BaseValidator.cs 3.6 KB

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