2 // System.Web.UI.WebControls.ValidationSummary.cs
5 // Gaurav Vaish (gvaish@iitk.ac.in)
6 // Andreas Nahr (ClassDevelopment@A-SoftTech.com)
8 // (C) Gaurav Vaish (2002)
9 // (C) 2003 Andreas Nahr
13 using System.ComponentModel;
\r
14 using System.Drawing;
\r
16 using System.Web.UI;
\r
18 namespace System.Web.UI.WebControls
\r
20 public class ValidationSummary : WebControl
\r
22 private bool uplevelRender;
\r
24 public ValidationSummary(): base(HtmlTextWriterTag.Div)
\r
26 uplevelRender = false;
\r
27 ForeColor = Color.Red;
\r
30 [DefaultValue (typeof (ValidationSummaryDisplayMode), "BulletList"), Bindable (true), WebCategory ("Appearance")]
31 [WebSysDescription ("The type of how validation summaries should be displayed.")]
\r
32 public ValidationSummaryDisplayMode DisplayMode
\r
36 object o = ViewState["DisplayMode"];
\r
38 return (ValidationSummaryDisplayMode)o;
\r
39 return ValidationSummaryDisplayMode.BulletList;
\r
43 if(!Enum.IsDefined(typeof(ValidationSummaryDisplayMode), value))
\r
44 throw new ArgumentException();
\r
45 ViewState["DisplayMode"] = value;
\r
49 [DefaultValue (true), WebCategory ("Behavior")]
50 [WebSysDescription ("Determines if the validation summary should be updated directly on the client using script code.")]
\r
51 public bool EnableClientScript
\r
55 object o = ViewState["EnableClientScript"];
\r
62 ViewState["EnableClientScript"] = value;
\r
66 [DefaultValue (null)]
\r
67 public override Color ForeColor
\r
71 return base.ForeColor;
\r
75 base.ForeColor = value;
\r
79 [DefaultValue (false), Bindable (true), WebCategory ("Behavior")]
80 [WebSysDescription ("Determines if the validation summary should display a message box on the client if an uplevel browser is used.")]
\r
81 public bool ShowMessageBox
\r
85 object o = ViewState["ShowMessageBox"];
\r
92 ViewState["ShowMessageBox"] = value;
\r
96 [DefaultValue (true), Bindable (true), WebCategory ("Behavior")]
97 [WebSysDescription ("Determines if the validation summary should display a summary.")]
\r
98 public bool ShowSummary
\r
102 object o = ViewState["ShowSummary"];
\r
109 ViewState["ShowSummary"] = value;
\r
113 [DefaultValue (""), Bindable (true), WebCategory ("Appearance")]
114 [WebSysDescription ("A text that is diplayed as a header for the validation report.")]
\r
115 public string HeaderText
\r
119 object o = ViewState["HeaderText"];
\r
122 return String.Empty;
\r
126 ViewState["HeaderText"] = value;
\r
130 protected override void AddAttributesToRender(HtmlTextWriter writer)
\r
132 base.AddAttributesToRender(writer);
\r
135 if(ID == null || ID.Length == 0)
\r
136 writer.AddAttribute("id", ClientID);
\r
137 if(HeaderText.Length > 0)
\r
138 writer.AddAttribute("headertext", HeaderText, true);
\r
140 writer.AddAttribute("showmessagebox", "True");
\r
142 writer.AddAttribute("showsummary", "False");
\r
143 if(DisplayMode != ValidationSummaryDisplayMode.BulletList)
\r
145 writer.AddAttribute("displaymode", PropertyConverter.EnumToString(typeof(ValidationSummaryDisplayMode), DisplayMode));
\r
150 protected override void OnPreRender(EventArgs e)
154 protected override void Render(HtmlTextWriter writer)
156 if (!base.Enabled) return;
162 if (base.Site != null && base.Site.DesignMode)
165 messages = new string[]{HttpRuntime.FormatResourceString("ValSummary_error_message_1"),
166 HttpRuntime.FormatResourceString("ValSummary_error_message_2")};
168 uplevelRender = false;
177 for (int i = 0; i < base.Page.Validators.Count; i++)
179 IValidator currentValidator = base.Page.Validators[i];
180 if (!currentValidator.IsValid)
183 if (currentValidator.ErrorMessage != null &&
184 currentValidator.ErrorMessage.Length != 0)
191 messages = new string[(int)numOfMsg];
193 for (int i = 0; i < base.Page.Validators.Count; i++)
195 IValidator currentValidator = base.Page.Validators[i];
196 if (!currentValidator.IsValid &&
197 currentValidator.ErrorMessage != null &&
198 currentValidator.ErrorMessage.Length != 0)
199 messages[cur_msg++] = String.Copy(currentValidator.ErrorMessage);
203 toDisplay = ShowSummary ? showSummary : false;
204 if (!toDisplay && uplevelRender)
205 base.Style["display"] = "none";
207 if (base.Page != null)
209 base.Page.VerifyRenderingInServerForm(this);
211 bool tagRequired = !uplevelRender ? toDisplay : true;
214 base.RenderBeginTag(writer);
218 string str1, str2, str3, str4, str5;
223 case ValidationSummaryDisplayMode.List:
231 case ValidationSummaryDisplayMode.SingleParagraph:
247 if (HeaderText.Length > 0)
249 writer.Write(HeaderText);
253 if (messages != null)
255 for (int i = 0; i < (int)messages.Length; i++)
258 writer.Write(messages[i]);
266 base.RenderEndTag(writer);