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
|
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Drawing;
namespace WindowsControlLibrary1
{
/// <summary>
/// Description résumée de TextField.
/// </summary>
[DefaultProperty("Text"), ToolboxData("<{0}:TextField runat=\"server\"></{0}:TextField>")]
public class TextField : TextBox
{
private bool _isControled = true;
private bool _isNotNull = false;
private bool _isReadOnly = false;
private RequiredFieldValidator req;
private RegularExpressionValidator reg;
[Bindable(true), Category("Data"), DefaultValue("")]
public string Value
{
get { return Text; }
set { Text = value; }
}
[Bindable(true), Category("Data"), DefaultValue(false)]
public override bool ReadOnly
{
get { return _isReadOnly; }
set { _isReadOnly = value; }
}
[Bindable(true), Category("Data"), DefaultValue(false)]
public bool IsNotNull
{
get { return _isNotNull; }
set { _isNotNull = value; }
}
[Bindable(true), Category("Data"), DefaultValue(true)]
public bool IsControled
{
get { return _isControled; }
set { _isControled = value; }
}
private void Control_Load(object sender, System.EventArgs e)
{
}
protected override void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
TextMode = TextBoxMode.SingleLine;
if (IsNotNull)
{
req = new RequiredFieldValidator();
req.ControlToValidate = this.ID;
req.ForeColor = new Color();
req.CssClass = "importantMessage";
req.EnableClientScript = true;
Controls.Add(req);
reg = new RegularExpressionValidator();
reg.ControlToValidate = this.ID;
reg.ErrorMessage = "Champ doit etre numerique";
reg.EnableClientScript = true;
reg.ValidationExpression = @"^[0-9]+$";
}
}
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Control_Load);
}
/// <summary>
/// Génére ce contrôle dans le paramètre de sortie spécifié.
/// </summary>
/// <param name="output"> Le writer HTML vers lequel écrire </param>
protected override void Render(HtmlTextWriter output)
{
if ((CssClass == null) || (CssClass == ""))
{
if (ReadOnly)
{
CssClass = "readOnly";
}
}
if (this.IsNotNull)
{
req.ErrorMessage = "Null Interdit";
req.RenderControl(output);
reg.RenderControl(output);
base.Render(output);
}
}
}
} |
Partager