The code is as follows
Using System;
Using System.Web;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.ComponentModel;
Using System.Text;
Namespace Dxh. Web.UI.WebControls
{
public enum textboxmode{
Singleline = 0,
MultiLine = 1,
Password = 2,
Hidden = 3
}
<summary>
A summary description of the TextBox.
</summary>
[ToolBoxData ("<{0}:textbox runat=server></{0}:textbox>")]
public class TextBox:System.Web.UI.WebControls.TextBox
{
[Browsable (False)]
public override System.Web.UI.WebControls.TextBoxMode TextMode
{
Get
{
Return base. TextMode;
}
Set
{
Base. TextMode = value;
}
}
[Description (Custom text box behavior pattern), DefaultValue (0), browsable (True), Category ("Behavior")]
Public TextBoxMode mode{
Get
{
Object TextMode = this. viewstate["TextMode"];
if (TextMode!= null)
{
Return ((TextBoxMode) textmode);
}
return textboxmode.singleline;
}
Set
{
if ((Value < textboxmode.singleline) | | (Value > Textboxmode.hidden))
{
throw new ArgumentOutOfRangeException ("value");
}
This. viewstate["TextMode"] = value;
if (value = = Textboxmode.hidden)
This. TextMode = (System.Web.UI.WebControls.TextBoxMode) textboxmode.singleline;
Else
This. TextMode = (System.Web.UI.WebControls.TextBoxMode) value;
}
}
[Description ("Value corrected for text"), DefaultValue (""), browsable (True), Category ("appearance")]
public string value{
Get{return Inputtext (base. Text,base. MaxLength);}
}
private string Inputtext (string inputstring, int maxLength)
{
StringBuilder retVal = new StringBuilder ();
if ((inputstring!= null) && (inputstring!= String.Empty))
{
InputString = Inputstring.trim ();
if (0!= maxLength && inputstring.length > MaxLength)
inputstring = inputstring.substring (0, maxLength);
for (int i = 0; i < inputstring.length; i++)
{
Switch (Inputstring[i])
{
Case ' "':
Retval.append ("" ");
Break
Case ' < ':
Retval.append ("<");
Break
Case ' > ':
Retval.append (">");
Break
Default
Retval.append (Inputstring[i]);
Break
}
}
Retval.replace ("'", "" ");
}
return retval.tostring ();
}
protected override void AddAttributesToRender (HtmlTextWriter writer)
{
if (this. Mode = = Textboxmode.hidden)
{
Writer. AddStyleAttribute ("Display", "none");
Writer. AddAttribute (Htmltextwriterattribute.type, "hidden");
}
Base. AddAttributesToRender (writer);
}
}
}