BaseValidator.cs 3.6 KB

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