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 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 using System.ComponentModel;
\r
35 using System.Drawing;
\r
37 using System.Web.UI;
\r
39 namespace System.Web.UI.WebControls
\r
41 public class ValidationSummary : WebControl
\r
43 private bool uplevelRender;
\r
45 public ValidationSummary(): base(HtmlTextWriterTag.Div)
\r
47 uplevelRender = false;
\r
48 ForeColor = Color.Red;
\r
54 [DefaultValue (typeof (ValidationSummaryDisplayMode), "BulletList"), WebCategory ("Appearance")]
55 [WebSysDescription ("The type of how validation summaries should be displayed.")]
\r
56 public ValidationSummaryDisplayMode DisplayMode
\r
60 object o = ViewState["DisplayMode"];
\r
62 return (ValidationSummaryDisplayMode)o;
\r
63 return ValidationSummaryDisplayMode.BulletList;
\r
67 if(!Enum.IsDefined(typeof(ValidationSummaryDisplayMode), value))
\r
68 throw new ArgumentException();
\r
69 ViewState["DisplayMode"] = value;
\r
74 [ThemeableAttribute (false)]
76 [DefaultValue (true), WebCategory ("Behavior")]
77 [WebSysDescription ("Determines if the validation summary should be updated directly on the client using script code.")]
\r
78 public bool EnableClientScript
\r
82 object o = ViewState["EnableClientScript"];
\r
89 ViewState["EnableClientScript"] = value;
\r
93 [DefaultValue (null)]
\r
94 public override Color ForeColor
\r
98 return base.ForeColor;
\r
102 base.ForeColor = value;
\r
109 [DefaultValue (false), WebCategory ("Behavior")]
110 [WebSysDescription ("Determines if the validation summary should display a message box on the client if an uplevel browser is used.")]
\r
111 public bool ShowMessageBox
\r
115 object o = ViewState["ShowMessageBox"];
\r
122 ViewState["ShowMessageBox"] = value;
\r
129 [DefaultValue (true), WebCategory ("Behavior")]
130 [WebSysDescription ("Determines if the validation summary should display a summary.")]
\r
131 public bool ShowSummary
\r
135 object o = ViewState["ShowSummary"];
\r
142 ViewState["ShowSummary"] = value;
\r
149 [DefaultValue (""), Bindable (true), WebCategory ("Appearance")]
150 [WebSysDescription ("A text that is diplayed as a header for the validation report.")]
\r
151 public string HeaderText
\r
155 object o = ViewState["HeaderText"];
\r
158 return String.Empty;
\r
162 ViewState["HeaderText"] = value;
\r
166 protected override void AddAttributesToRender(HtmlTextWriter writer)
\r
168 base.AddAttributesToRender(writer);
\r
171 if(ID == null || ID.Length == 0)
\r
172 writer.AddAttribute("id", ClientID);
\r
173 if(HeaderText.Length > 0)
\r
174 writer.AddAttribute("headertext", HeaderText, true);
\r
176 writer.AddAttribute("showmessagebox", "True");
\r
178 writer.AddAttribute("showsummary", "False");
\r
179 if(DisplayMode != ValidationSummaryDisplayMode.BulletList)
\r
181 writer.AddAttribute("displaymode", PropertyConverter.EnumToString(typeof(ValidationSummaryDisplayMode), DisplayMode));
\r
186 protected override void OnPreRender(EventArgs e)
190 protected override void Render(HtmlTextWriter writer)
192 if (!base.Enabled) return;
198 if (base.Site != null && base.Site.DesignMode)
201 messages = new string[]{HttpRuntime.FormatResourceString("ValSummary_error_message_1"),
202 HttpRuntime.FormatResourceString("ValSummary_error_message_2")};
204 uplevelRender = false;
213 for (int i = 0; i < base.Page.Validators.Count; i++)
215 IValidator currentValidator = base.Page.Validators[i];
216 if (!currentValidator.IsValid)
219 if (currentValidator.ErrorMessage != null &&
220 currentValidator.ErrorMessage.Length != 0)
227 messages = new string[(int)numOfMsg];
229 for (int i = 0; i < base.Page.Validators.Count; i++)
231 IValidator currentValidator = base.Page.Validators[i];
232 if (!currentValidator.IsValid &&
233 currentValidator.ErrorMessage != null &&
234 currentValidator.ErrorMessage.Length != 0)
235 messages[cur_msg++] = String.Copy(currentValidator.ErrorMessage);
239 toDisplay = ShowSummary ? showSummary : false;
240 if (!toDisplay && uplevelRender)
241 base.Style["display"] = "none";
243 if (base.Page != null)
245 base.Page.VerifyRenderingInServerForm(this);
247 bool tagRequired = !uplevelRender ? toDisplay : true;
250 base.RenderBeginTag(writer);
254 string str1, str2, str3, str4, str5;
259 case ValidationSummaryDisplayMode.List:
267 case ValidationSummaryDisplayMode.SingleParagraph:
283 if (HeaderText.Length > 0)
285 writer.Write(HeaderText);
289 if (messages != null)
291 for (int i = 0; i < (int)messages.Length; i++)
294 writer.Write(messages[i]);
302 base.RenderEndTag(writer);