To add a hidden property to the textbox, the Value property

Source: Internet
Author: User
Tags string
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);

}

}
}





Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.