2003-07-30 Andreas Nahr <ClassDevelopment@A-SoftTech.com>
[mono.git] / mcs / class / System.Web / System.Web.UI.WebControls / ValidationSummary.cs
1 //
2 // System.Web.UI.WebControls.ValidationSummary.cs
3 //
4 // Authors:
5 //   Gaurav Vaish (gvaish@iitk.ac.in)
6 //   Andreas Nahr (ClassDevelopment@A-SoftTech.com)
7 //
8 // (C) Gaurav Vaish (2002)
9 // (C) 2003 Andreas Nahr
10 //\r
11 \r
12 using System;
13 using System.ComponentModel;\r
14 using System.Drawing;\r
15 using System.Web;\r
16 using System.Web.UI;\r
17 \r
18 namespace System.Web.UI.WebControls\r
19 {\r
20         public class ValidationSummary : WebControl\r
21         {\r
22                 private bool uplevelRender;\r
23 \r
24                 public ValidationSummary(): base(HtmlTextWriterTag.Div)\r
25                 {\r
26                         uplevelRender = false;\r
27                         ForeColor     = Color.Red;\r
28                 }\r
29
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
33                 {\r
34                         get\r
35                         {\r
36                                 object o = ViewState["DisplayMode"];\r
37                                 if(o != null)\r
38                                         return (ValidationSummaryDisplayMode)o;\r
39                                 return ValidationSummaryDisplayMode.BulletList;\r
40                         }\r
41                         set\r
42                         {\r
43                                 if(!Enum.IsDefined(typeof(ValidationSummaryDisplayMode), value))\r
44                                         throw new ArgumentException();\r
45                                 ViewState["DisplayMode"] = value;\r
46                         }\r
47                 }\r
48
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
52                 {\r
53                         get\r
54                         {\r
55                                 object o = ViewState["EnableClientScript"];\r
56                                 if(o != null)\r
57                                         return (bool)o;\r
58                                 return true;\r
59                         }\r
60                         set\r
61                         {\r
62                                 ViewState["EnableClientScript"] = value;\r
63                         }\r
64                 }\r
65
66                 [DefaultValue (null)]\r
67                 public override Color ForeColor\r
68                 {\r
69                         get\r
70                         {\r
71                                 return ForeColor;\r
72                         }\r
73                         set\r
74                         {\r
75                                 ForeColor = value;\r
76                         }\r
77                 }\r
78
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
82                 {\r
83                         get\r
84                         {\r
85                                 object o = ViewState["ShowMessageBox"];\r
86                                 if(o != null)\r
87                                         return (bool)o;\r
88                                 return false;\r
89                         }\r
90                         set\r
91                         {\r
92                                 ViewState["ShowMessageBox"] = value;\r
93                         }\r
94                 }\r
95
96                 [DefaultValue (true), Bindable (true), WebCategory ("Behavior")]
97                 [WebSysDescription ("Determines if the validation summary should display a summary.")]\r
98                 public bool ShowSummary\r
99                 {\r
100                         get\r
101                         {\r
102                                 object o = ViewState["ShowSummary"];\r
103                                 if(o != null)\r
104                                         return (bool)o;\r
105                                 return true;\r
106                         }\r
107                         set\r
108                         {\r
109                                 ViewState["ShowSummary"] = value;\r
110                         }\r
111                 }\r
112
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
116                 {\r
117                         get\r
118                         {\r
119                                 object o = ViewState["HeaderText"];\r
120                                 if(o != null)\r
121                                         return (string)o;\r
122                                 return String.Empty;\r
123                         }\r
124                         set\r
125                         {\r
126                                 ViewState["HeaderText"] = value;\r
127                         }\r
128                 }\r
129 \r
130                 [MonoTODO("FIXME_See_Comments")]\r
131                 protected override void AddAttributesToRender(HtmlTextWriter writer)\r
132                 {\r
133                         AddAttributesToRender(writer);\r
134                         if(uplevelRender)\r
135                         {\r
136                                 //FIXME: This is not the case always. I forgot the case when it is absent.\r
137                                 // something to do with the ID's value? or ClienID's value itself?\r
138                                 writer.AddAttribute("id", ClientID);\r
139                                 if(HeaderText.Length > 0)\r
140                                         writer.AddAttribute("headertext", HeaderText, true);\r
141                                 if(ShowMessageBox)\r
142                                         writer.AddAttribute("showmessagebox", "True");\r
143                                 if(!ShowSummary)\r
144                                         writer.AddAttribute("showsummary", "False");\r
145                                 if(DisplayMode != ValidationSummaryDisplayMode.BulletList)\r
146                                 {\r
147                                         writer.AddAttribute("displaymode", PropertyConverter.EnumToString(typeof(ValidationSummaryDisplayMode), DisplayMode));\r
148                                 }\r
149                         }\r
150                 }\r
151         }\r
152 }\r