This repository was archived by the owner on Oct 25, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTextBox.cs
125 lines (105 loc) · 3.14 KB
/
TextBox.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace BootstrapControls
{
[DefaultProperty("Text")]
[ToolboxData("<{0}:TextBox runat=server></{0}:TextBox>")]
public class TextBox : System.Web.UI.WebControls.TextBox
{
public string Name
{
get
{
if (ViewState["TextboxName_" + this.ID] != null)
return ViewState["TextboxName_" + this.ID].ToString();
else
return string.Empty;
}
set
{
ViewState["TextboxName_" + this.ID] = value;
}
}
public string Message { get; set; }
private string _Size { get; set; }
public InputSize Size
{
set
{
if (value == InputSize.Small)
_Size = "form-group-sm";
if (value == InputSize.Normal)
_Size = string.Empty;
if (value == InputSize.Big)
_Size = "form-group-lg";
}
}
private string _State { get; set; }
private string _MessageColor { get; set; }
public InputOption State
{
set
{
_State = " has-" + value.ToString().ToLower();
if (value == InputOption.Error)
{
_MessageColor = "text-danger";
}
else
{
_MessageColor = "text-" + value.ToString().ToLower();
}
}
}
public bool? FormGroup
{
get; set;
}
public string Ico
{
get
{
return IcoLeft;
}
set
{
IcoLeft = value;
}
}
public string IcoLeft
{
get; set;
}
public string Placeholder
{
set
{
base.Attributes["placeholder"] = value;
}
}
protected override void Render(HtmlTextWriter w)
{
w.Write(String.Format(@"<div class=""{2} {0} {1}"">", _Size, _State, (FormGroup.HasValue) ? ((FormGroup.Value) ? "form-group" : "") : "form-group"));
if(!string.IsNullOrWhiteSpace(Name))
w.Write(String.Format(@"<label class=""control-label"" for=""{0}"">{1}</label>", base.ClientID, this.Name));
if (IcoLeft != null)
{
w.Write(@"<div class=""input-group"">");
w.Write(String.Format(@"<div class=""input-group-addon"">{0}</div>", IcoLeft));
}
base.CssClass += " form-control";
base.Render(w);
if (IcoLeft != null)
w.Write("</div>");
if (Message != null)
w.Write(String.Format(@"<p class=""help-block {0}"">{1}</p>", _MessageColor, Message ));
w.Write("</div>");
}
}
}