ValidationSummary.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. //
  2. // System.Web.UI.WebControls.ValidationSummary.cs
  3. //
  4. // Authors:
  5. // Gaurav Vaish ([email protected])
  6. // Andreas Nahr ([email protected])
  7. //
  8. // (C) Gaurav Vaish (2002)
  9. // (C) 2003 Andreas Nahr
  10. //
  11. using System;
  12. using System.ComponentModel;
  13. using System.Drawing;
  14. using System.Web;
  15. using System.Web.UI;
  16. namespace System.Web.UI.WebControls
  17. {
  18. public class ValidationSummary : WebControl
  19. {
  20. private bool uplevelRender;
  21. public ValidationSummary(): base(HtmlTextWriterTag.Div)
  22. {
  23. uplevelRender = false;
  24. ForeColor = Color.Red;
  25. }
  26. [DefaultValue (typeof (ValidationSummaryDisplayMode), "BulletList"), Bindable (true), WebCategory ("Appearance")]
  27. [WebSysDescription ("The type of how validation summaries should be displayed.")]
  28. public ValidationSummaryDisplayMode DisplayMode
  29. {
  30. get
  31. {
  32. object o = ViewState["DisplayMode"];
  33. if(o != null)
  34. return (ValidationSummaryDisplayMode)o;
  35. return ValidationSummaryDisplayMode.BulletList;
  36. }
  37. set
  38. {
  39. if(!Enum.IsDefined(typeof(ValidationSummaryDisplayMode), value))
  40. throw new ArgumentException();
  41. ViewState["DisplayMode"] = value;
  42. }
  43. }
  44. [DefaultValue (true), WebCategory ("Behavior")]
  45. [WebSysDescription ("Determines if the validation summary should be updated directly on the client using script code.")]
  46. public bool EnableClientScript
  47. {
  48. get
  49. {
  50. object o = ViewState["EnableClientScript"];
  51. if(o != null)
  52. return (bool)o;
  53. return true;
  54. }
  55. set
  56. {
  57. ViewState["EnableClientScript"] = value;
  58. }
  59. }
  60. [DefaultValue (null)]
  61. public override Color ForeColor
  62. {
  63. get
  64. {
  65. return ForeColor;
  66. }
  67. set
  68. {
  69. ForeColor = value;
  70. }
  71. }
  72. [DefaultValue (false), Bindable (true), WebCategory ("Behavior")]
  73. [WebSysDescription ("Determines if the validation summary should display a message box on the client if an uplevel browser is used.")]
  74. public bool ShowMessageBox
  75. {
  76. get
  77. {
  78. object o = ViewState["ShowMessageBox"];
  79. if(o != null)
  80. return (bool)o;
  81. return false;
  82. }
  83. set
  84. {
  85. ViewState["ShowMessageBox"] = value;
  86. }
  87. }
  88. [DefaultValue (true), Bindable (true), WebCategory ("Behavior")]
  89. [WebSysDescription ("Determines if the validation summary should display a summary.")]
  90. public bool ShowSummary
  91. {
  92. get
  93. {
  94. object o = ViewState["ShowSummary"];
  95. if(o != null)
  96. return (bool)o;
  97. return true;
  98. }
  99. set
  100. {
  101. ViewState["ShowSummary"] = value;
  102. }
  103. }
  104. [DefaultValue (""), Bindable (true), WebCategory ("Appearance")]
  105. [WebSysDescription ("A text that is diplayed as a header for the validation report.")]
  106. public string HeaderText
  107. {
  108. get
  109. {
  110. object o = ViewState["HeaderText"];
  111. if(o != null)
  112. return (string)o;
  113. return String.Empty;
  114. }
  115. set
  116. {
  117. ViewState["HeaderText"] = value;
  118. }
  119. }
  120. protected override void AddAttributesToRender(HtmlTextWriter writer)
  121. {
  122. AddAttributesToRender(writer);
  123. if(uplevelRender)
  124. {
  125. if(ID == null || ID.Length == 0)
  126. writer.AddAttribute("id", ClientID);
  127. if(HeaderText.Length > 0)
  128. writer.AddAttribute("headertext", HeaderText, true);
  129. if(ShowMessageBox)
  130. writer.AddAttribute("showmessagebox", "True");
  131. if(!ShowSummary)
  132. writer.AddAttribute("showsummary", "False");
  133. if(DisplayMode != ValidationSummaryDisplayMode.BulletList)
  134. {
  135. writer.AddAttribute("displaymode", PropertyConverter.EnumToString(typeof(ValidationSummaryDisplayMode), DisplayMode));
  136. }
  137. }
  138. }
  139. }
  140. }