| |||||||||||||||||
Source File | Conditionals | Statements | Methods | TOTAL | |||||||||||||
Web\WebControls\TextField.cs | 100,0 % | 82,8 % | 58,3 % | 78,7 % |
|
1 | #region Copyright | |
2 | /* | |
3 | ShowX. Maps business objects into presentation layer. | |
4 | Copyright (C) 2005 Jesus Diaz. | |
5 | ||
6 | This library is free software; you can redistribute it and/or | |
7 | modify it under the terms of the GNU Lesser General Public | |
8 | License as published by the Free Software Foundation; either | |
9 | version 2.1 of the License, or (at your option) any later version. | |
10 | ||
11 | This library is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | Lesser General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU Lesser General Public | |
17 | License along with this library; if not, write to the Free Software | |
18 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. | |
19 | ||
20 | For project details see: http://showx.sourceforge.net | |
21 | */ | |
22 | #endregion | |
23 | ||
24 | using System.ComponentModel; | |
25 | using System.Web.UI; | |
26 | using System.Web.UI.WebControls; | |
27 | using ShowX.Model; | |
28 | ||
29 | namespace ShowX.Web.WebControls | |
30 | { | |
31 | /// <summary> | |
32 | /// ChangePassword control defines a box useful to update a user password, with | |
33 | /// equality checking. | |
34 | /// </summary> | |
35 | [DefaultProperty("Text"), | |
36 | ToolboxData("<{0}:TextField runat=server></{0}:TextField>")] | |
37 | public class TextField : ValidatedControl | |
38 | { | |
39 | /// <summary> | |
40 | /// Textbox to store text | |
41 | /// </summary> | |
42 | protected TextBox textBox; | |
43 | ||
44 | /// <summary> | |
45 | /// Constructor | |
46 | /// </summary> | |
47 | 83 | public TextField() |
48 | { | |
49 | 83 | Controls.Add(textBox = new TextBox()); |
50 | 83 | textBox.Width = Unit.Percentage(100); |
51 | } | |
52 | ||
53 | /// <summary> | |
54 | /// Allow to check whether the password entered are valid | |
55 | /// </summary> | |
56 | /// <returns>True if the input value is te same, false otherwise</returns> | |
57 | 16 | public override bool Validate(object context) |
58 | { | |
59 | 16 | string message = string.Empty; |
60 | 16 | Validated = true; |
61 | ||
62 | 16 | foreach(IValidationMap val in Validators) { |
63 | ||
64 | 20 | if (!val.Validate(context,textBox.Text)) |
65 | 4 | message += val.Message + ","; |
66 | } | |
67 | ||
68 | 16 | if (message != string.Empty) { |
69 | ||
70 | 4 | Validated = false; |
71 | 4 | message = message.TrimEnd(new char[]{','}); |
72 | } | |
73 | ||
74 | 16 | messageL.Text = message; |
75 | 16 | return Validated; |
76 | } | |
77 | ||
78 | /// <summary> | |
79 | /// Reflex the text show on control. | |
80 | /// </summary> | |
81 | public string InputText | |
82 | { | |
83 | 20 | get { return textBox.Text; } |
84 | 8 | set { textBox.Text = value; } |
85 | } | |
86 | ||
87 | /// <summary> | |
88 | /// Merge current styles with a new one. | |
89 | /// </summary> | |
90 | /// <param name="style">New style to merge.</param> | |
91 | 83 | public override void MergeControlStyle(Style style) |
92 | { | |
93 | 83 | textBox.MergeStyle(style); |
94 | } | |
95 | ||
96 | /// <summary> | |
97 | /// TextMode of the TextField (delegates over the internal TextBox TextMode. | |
98 | /// </summary> | |
99 | 0 | public TextBoxMode TextMode |
100 | { | |
101 | get { return this.textBox.TextMode; } | |
102 | set { textBox.TextMode = value; } | |
103 | } | |
104 | ||
105 | /// <summary> | |
106 | /// Width of the TextField (delegates over the internal TextBox width. | |
107 | /// </summary> | |
108 | public override Unit Width | |
109 | { | |
110 | 0 | get |
111 | { | |
112 | return textBox.Width; | |
113 | } | |
114 | 8 | set |
115 | { | |
116 | 8 | textBox.Width = value; |
117 | } | |
118 | } | |
119 | ||
120 | /// <summary> | |
121 | /// Height of the TextField (delegates over the internal TextBox height. | |
122 | /// </summary> | |
123 | 0 | public override Unit Height |
124 | { | |
125 | get | |
126 | { | |
127 | return textBox.Height; | |
128 | } | |
129 | set | |
130 | { | |
131 | textBox.Height = value; | |
132 | } | |
133 | } | |
134 | ||
135 | ||
136 | ||
137 | /// <summary> | |
138 | /// Method Render is in charge of render the control to html code | |
139 | /// </summary> | |
140 | /// <param name="writer">Writer to output html code</param> | |
141 | 72 | protected override void Render(HtmlTextWriter writer) |
142 | { | |
143 | 72 | writer.Write(@" |
144 | <table border=0 cellpadding=0 width=100%> | |
145 | <tbody> | |
146 | <tr> | |
147 | <td>"); | |
148 | ||
149 | 72 | textBox.RenderControl(writer); |
150 | ||
151 | 72 | writer.Write(@" |
152 | </td> | |
153 | </tr>"); | |
154 | ||
155 | 72 | if (!Validated) { |
156 | ||
157 | 4 | writer.Write(@" |
158 | <tr> | |
159 | <td>"); | |
160 | ||
161 | 4 | messageL.RenderControl(writer); |
162 | 4 | writer.Write(@" |
163 | </td> | |
164 | </tr>"); | |
165 | ||
166 | } | |
167 | 72 | writer.Write(@" |
168 | </tbody> | |
169 | </table>"); | |
170 | } | |
171 | } | |
172 | } | |
173 |
|