using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.ComponentModel;
using System.Collections;
using System.Text.RegularExpressions;
using System.Runtime.InteropServices;
using System.Globalization;
using System.Threading;
namespace Extendedtextbox
{
/// <summary>
/// Summary description for WebCustomControl1.
/// </summary>
///
[DefaultProperty("Text"),
ToolboxData("<{0}:Maskedtextbox runat=server></{0}:Maskedtextbox>")]
public class Maskedtextbox : System.Web.UI.TemplateControl
{
private string text;
private TextBox tx1 = new TextBox();
private TextBox tx2 = new TextBox();
private TextBox tx3 = new TextBox();
private TextBox tx4 = new TextBox();
private Label lb1 = new Label();
private DropDownList dd1 = new DropDownList();
private HtmlInputHidden HdnType = new HtmlInputHidden();
private HtmlInputHidden hdnwidth = new HtmlInputHidden();
private HtmlInputHidden hdnmaxlenth = new HtmlInputHidden();
private HtmlInputHidden hdnextn = new HtmlInputHidden();
private HtmlInputHidden hdncss = new HtmlInputHidden();
private HtmlInputHidden hdntxmode = new HtmlInputHidden();
private HtmlInputHidden hdnselcardtype = new HtmlInputHidden();
public enum boolean{False, True};
public enum textmode{SingleLine, MultiLine};
//private boolean m_bool;
private string classtype;
private string controltype;
private int maxlength;
private int width;
private textmode m_textmode;
private string cssclass;
private boolean extnneeded;
private string strculture;
public string Text
{
get
{
if(controltype == "IP Address")
text = this.tx1.Text+"."+this.tx2.Text+"."+this.tx3.Text+"."+this.tx4.Text;
else if(controltype == "Phone" && extnneeded == boolean.True)
text = this.tx1.Text+"-"+this.tx2.Text+"-"+this.tx3.Text+"-"+this.tx4.Text;
else if(controltype == "Phone" && extnneeded == boolean.False)
text = this.tx1.Text+"-"+this.tx2.Text+"-"+this.tx3.Text;
else if(controltype == "Alpha Only")
text = this.tx1.Text;
else if(controltype == "Numeric Only")
text = this.tx1.Text;
else if(controltype == "Alphanumeric")
text = this.tx1.Text;
else if(controltype == "SSN")
text = this.tx1.Text+"-"+this.tx2.Text+"-"+this.tx3.Text;
else if(controltype == "Credit Card")
text = System.Web.HttpContext.Current.Request[this.ClientID+":tx1"].ToString()+System.Web.HttpContext.Current.Request[this.ClientID+":tx2"].ToString()+System.Web.HttpContext.Current.Request[this.ClientID+":tx3"].ToString()+System.Web.HttpContext.Current.Request[this.ClientID+":tx4"].ToString();
else if(controltype == "Money")
text = this.tx1.Text;
return text;
}
set
{
text = value;
if(controltype == "IP Address")
{
string[] split = null;
split = text.Split('.');
if(split[0].Length > 3 || !IsNumber(split[0]))
throw new ArgumentException("This is not a valid IP address");
this.tx1.Text = split[0];
if(split[1].Length > 3 || !IsNumber(split[1]))
throw new ArgumentException("This is not a valid IP address");
this.tx2.Text = split[1];
if(split[2].Length > 3 || !IsNumber(split[2]))
throw new ArgumentException("This is not a valid IP address");
this.tx3.Text = split[2];
if(split[3].Length > 3 || !IsNumber(split[3]))
throw new ArgumentException("This is not a valid IP address");
this.tx4.Text = split[3];
}
else if(controltype == "Phone" && extnneeded == boolean.True)
{
string[] split = null;
split = text.Split('-');
if(split[0].Length > 3 || !IsNumber(split[0]))
throw new ArgumentException("This is not a valid Telephone number");
this.tx1.Text = split[0];
if(split[1].Length > 3 || !IsNumber(split[1]))
throw new ArgumentException("This is not a valid Telephone number");
this.tx2.Text = split[1];
if(split[2].Length > 4 || !IsNumber(split[2]))
throw new ArgumentException("This is not a valid Telephone number");
this.tx3.Text = split[2];
if(split[3].Length > 4 || !IsNumber(split[3]))
throw new ArgumentException("This is not a valid Telephone number");
this.tx4.Text = split[3];
}
else if(controltype == "Phone" && extnneeded == boolean.False)
{
string[] split = null;
split = text.Split('-');
if(split[0].Length > 3 || !IsNumber(split[0]))
throw new ArgumentException("This is not a valid Telephone number");
this.tx1.Text = split[0];
if(split[1].Length > 3 || !IsNumber(split[1]))
throw new ArgumentException("This is not a valid Telephone number");
this.tx2.Text = split[1];
if(split[2].Length > 4 || !IsNumber(split[2]))
throw new ArgumentException("This is not a valid Telephone number");
this.tx3.Text = split[2];
}
else if(controltype == "Alpha Only")
{
if(!IsAlpha(text))
throw new ArgumentException("Text contains in-valid alpha charaters");
this.tx1.Text = text;
}
else if(controltype == "Numeric Only")
{
if(!IsNumber(text))
throw new ArgumentException("Text contains in-valid numeric charaters");
this.tx1.Text = text;
}
else if(controltype == "Alphanumeric")
{
if(!IsAlphaNumeric(text))
throw new ArgumentException("Text contains in-valid alphanumeric charaters");
this.tx1.Text = text;
}
else if(controltype == "SSN")
{
string[] split = null;
split = text.Split('-');
if(split[0].Length > 3 || !IsNumber(split[0]))
throw new ArgumentException("This is not a valid SSN");
this.tx1.Text = split[0];
if(split[1].Length > 2 || !IsNumber(split[1]))
throw new ArgumentException("This is not a valid SSN");
this.tx2.Text = split[1];
if(split[2].Length > 4 || !IsNumber(split[2]))
throw new ArgumentException("This is not a valid SSN");
this.tx3.Text = split[2];
}
else if(controltype == "Money")
{
if(!IsMoney(text))
throw new ArgumentException("Text contains in-valid numeric charaters");
this.tx1.Text = text;
}
}
}
[Bindable(true),
Category("Masked TextBox"),
DefaultValue(""), Description("Type of control to be rendered")]
[TypeConverter(typeof(ControltypeConverter))]
public string ControlType
{
get
{
return this.controltype;
}
set
{
if(value.GetType() == typeof(string))
{
this.controltype = value;
//this.HdnCtrlType.Value = value;
}
}
}
[Bindable(true),
Category("Masked TextBox"),Browsable(true),
DefaultValue(""), Description("IP Address class type (applicable only for IP Address textbox)")]
[TypeConverter(typeof(ClasstypeConverter))]
public string ClassType
{
get
{
return this.classtype;
}
set
{
if(value.GetType() == typeof(string))
{
this.classtype = value;
this.HdnType.Value = value;
}
}
}
[Bindable(true),
Category("Masked TextBox"),Browsable(true),
Description("The maximum number of characters that can be entered (not Applicable for IP Address, Telephone, SSN)")]
public int MaxLength
{
get
{
return this.maxlength;
}
set
{
if(value.GetType() == typeof(int))
{
if(value != 0)
{
this.maxlength = value;
this.hdnmaxlenth.Value = value.ToString();
}
else
{
this.maxlength = 50;
this.hdnmaxlenth.Value = "50";
}
}
}
}
[Bindable(true),
Category("Masked TextBox"),Browsable(true),
Description("Width of the control (not Applicable for IP Address, Telephone, SSN)")]
public int Width
{
get
{
return this.width;
}
set
{
if(value.GetType() == typeof(int))
{
if(value != 0)
{
this.width = value;
this.hdnwidth.Value = value.ToString();
}
else
{
this.width = 50;
this.hdnwidth.Value = "50";
}
}
}
}
[Bindable(true),
Category("Masked TextBox"),Browsable(true),
Description("The behaviour of textbox (not applicable for IP Address, Telephone, SSN)")]
public textmode TextMode
{
get
{
if(this.m_textmode == textmode.MultiLine)
return textmode.MultiLine;
else
return textmode.SingleLine;
}
set
{
this.m_textmode = value;
}
}
[Bindable(true),
Category("Masked TextBox"),Browsable(true),
DefaultValue(""), Description("CSS Class name applied to the control")]
public string CssClass
{
get
{
return this.cssclass;
}
set
{
if(value.GetType() == typeof(string))
{
if(value.Length != 0)
{
this.cssclass = value;
this.hdncss.Value = value;
}
else
{
this.cssclass = "";
this.hdncss.Value = "";
}
}
}
}
[Bindable(true),
Category("Masked TextBox"),Browsable(true),
Description("Telephone number extension needed (applicable only for Telephone)")]
public boolean ExtnNeeded
{
get
{
if(this.extnneeded == boolean.True)
return boolean.True;
else
return boolean.False;
}
set
{
this.extnneeded= value;
this.hdnextn.Value = value.ToString();
}
}
[Bindable(true),
Category("Masked TextBox"),Browsable(false),
Description("Selected card type (applicable only for Credit Card)")]
public string SelectedCard
{
get
{
if(controltype == "Crdeit Card")
return this.dd1.SelectedValue;
else
return "";
}
set
{
if(controltype == "Crdeit Card")
dd1.SelectedValue = value;
}
}
[Bindable(true),
Category("Masked TextBox"),Browsable(true),
Description("CultureInfo (applicable only for Money)")]
public string CultureInfo
{
get
{
if(controltype == "Money")
return this.strculture;
else
return "en-US";
}
set
{
if(controltype == "Money" && value.Length != 0)
this.strculture = value;
else
this.strculture = "en-US";
}
}
//classtype
/// <summary>
/// Render this control to the output parameter specified.
/// </summary>
/// <param name="output"> The HTML writer to write out to </param>
protected override void Render(HtmlTextWriter output)
{
RenderChildren(output);
}
protected override void RenderChildren(HtmlTextWriter output)
{
if (HasControls())
{
/// Render Children in reverse order.
for(int i = 0; i <Controls.Count; i++)
{
Controls[i].RenderControl(output);
}
}
//base.Render(output);
}
protected override void CreateChildControls()
{
this.Controls.Add(hdncss);
this.Controls.Add(hdnmaxlenth);
this.Controls.Add(hdnwidth);
this.Controls.Add(hdntxmode);
this.Controls.Add(hdnextn);
this.Controls.Add(new LiteralControl("<script type=\"text/javascript\" language=\"JavaScript1.2\" src=\"Masked.js\"></script>"));
if(controltype == "IP Address")
{
HdnType.ID = "HdnType";
HdnType.Value = classtype;
this.Controls.Add(HdnType);
//tx1 = new TextBox();
tx1.ID = "tx1";
tx1.Style.Add("BORDER-RIGHT", "0px solid");
tx1.Style.Add("BORDER-TOP", "0px solid");
tx1.Style.Add("BORDER-LEFT", "0px solid");
tx1.Style.Add("BORDER-BOTTOM", "0px solid");
tx1.MaxLength = 3;
tx1.EnableViewState = true;
tx1.Attributes.Add("onKeyUp", "return autoTab(this, 3, event);");
tx1.Attributes.Add("onBlur", "return autoChecknumC(this);");
tx1.Width = 25;
//tx2 = new TextBox();
tx2.ID = "tx2";
tx2.Style.Add("BORDER-RIGHT", "0px solid");
tx2.Style.Add("BORDER-TOP", "0px solid");
tx2.Style.Add("BORDER-LEFT", "0px solid");
tx2.Style.Add("BORDER-BOTTOM", "0px solid");
tx2.MaxLength = 3;
tx2.Attributes.Add("onKeyUp", "return autoTab(this, 3, event);");
tx2.Attributes.Add("onBlur", "return autoChecknumC(this);");
tx2.Width = 25;
//tx3 = new TextBox();
tx3.ID = "tx3";
tx3.Style.Add("BORDER-RIGHT", "0px solid");
tx3.Style.Add("BORDER-TOP", "0px solid");
tx3.Style.Add("BORDER-LEFT", "0px solid");
tx3.Style.Add("BORDER-BOTTOM", "0px solid");
tx3.MaxLength = 3;
tx3.Attributes.Add("onKeyUp", "return autoTab(this, 3, event);");
tx3.Attributes.Add("onBlur", "return autoChecknumC(this);");
tx3.Width = 25;
//tx4 = new TextBox();
tx4.ID = "tx4";
tx4.Style.Add("BORDER-RIGHT", "0px solid");
tx4.Style.Add("BORDER-TOP", "0px solid");
tx4.Style.Add("BORDER-LEFT", "0px solid");
tx4.Style.Add("BORDER-BOTTOM", "0px solid");
tx4.MaxLength = 3;
tx4.Attributes.Add("onKeyUp", "return autoTab(this, 3, event);");
tx4.Attributes.Add("onBlur", "return autoChecknumC(this);");
tx4.Width = 25;
this.Controls.Add(new LiteralControl("<table style=\"BORDER-RIGHT: black 1px solid; BORDER-TOP: black 1px solid; BORDER-LEFT: black 1px solid; BORDER-BOTTOM: black 1px solid\" cellSpacing=\"0\" cellPadding=\"0\"><tr>"));
this.Controls.Add(new LiteralControl("<td>"));
this.Controls.Add(tx1);
this.Controls.Add(new LiteralControl("</td>"));
this.Controls.Add(new LiteralControl("<td>.</td>"));
this.Controls.Add(new LiteralControl("<td>"));
this.Controls.Add(tx2);
this.Controls.Add(new LiteralControl("</td>"));
this.Controls.Add(new LiteralControl("<td>.</td>"));
this.Controls.Add(new LiteralControl("<td>"));
this.Controls.Add(tx3);
this.Controls.Add(new LiteralControl("</td>"));
this.Controls.Add(new LiteralControl("<td>.</td>"));
this.Controls.Add(new LiteralControl("<td>"));
this.Controls.Add(tx4);
this.Controls.Add(new LiteralControl("</td></tr></table>"));
text = tx1.Text+"."+tx2.Text+"."+tx3.Text+"."+tx4.Text;
}
else if(controltype == "Numeric Only")
{
tx1.ID = "tx1";
if(cssclass!=null && cssclass.Length !=0)
tx1.CssClass = cssclass;
tx1.MaxLength = maxlength;
if(m_textmode == textmode.MultiLine)
tx1.TextMode = TextBoxMode.MultiLine;
else
tx1.TextMode = TextBoxMode.SingleLine;
tx1.EnableViewState = true;
tx1.Attributes.Add("onKeyUp", "return autoChecknum(this);");
tx1.Attributes.Add("onBlur", "return autoChecknumC(this);");
if(width < 50)
tx1.Width = 50;
else
tx1.Width = width;
this.Controls.Add(tx1);
text = tx1.Text;
}
else if(controltype == "Money")
{
tx1.ID = "tx1";
if(cssclass!=null && cssclass.Length !=0)
tx1.CssClass = cssclass;
tx1.MaxLength = maxlength;
if(m_textmode == textmode.MultiLine)
tx1.TextMode = TextBoxMode.MultiLine;
else
tx1.TextMode = TextBoxMode.SingleLine;
try
{
CultureInfo myCIintl = new CultureInfo( strculture, false );
Thread.CurrentThread.CurrentCulture = myCIintl;
}
catch(Exception ex)
{
throw new ArgumentException("The given Culture name is not supported");
}
lb1.Text = 0.ToString("C").Replace("0.00","").Replace("0","").Replace(", ","").Trim();
tx1.EnableViewState = true;
tx1.Attributes.Add("onKeyUp", "return autoCheckMoney(this);");
tx1.Attributes.Add("onBlur", "return autoCheckMoneyC(this);");
if(width < 50)
tx1.Width = 50;
else
tx1.Width = width;
this.Controls.Add(tx1);
this.Controls.Add(lb1);
text = tx1.Text;
}
else if(controltype == "Alpha Only")
{
//tx1 = new TextBox();
tx1.ID = "tx1";
if(cssclass!=null && cssclass.Length !=0)
tx1.CssClass = cssclass;
tx1.MaxLength = maxlength;
if(m_textmode == textmode.MultiLine)
tx1.TextMode = TextBoxMode.MultiLine;
else
tx1.TextMode = TextBoxMode.SingleLine;
tx1.EnableViewState = true;
tx1.Attributes.Add("onKeyUp", "return autoCheckalp(this);");
tx1.Attributes.Add("onBlur", "return autoCheckalpC(this);");
if(width < 50)
tx1.Width = 50;
else
tx1.Width = width;
this.Controls.Add(tx1);
text = tx1.Text;
}
else if(controltype == "Alphanumeric")
{
//tx1 = new TextBox();
tx1.ID = "tx1";
if(cssclass!=null && cssclass.Length !=0)
tx1.CssClass = cssclass;
tx1.MaxLength = maxlength;
if(m_textmode == textmode.MultiLine)
tx1.TextMode = TextBoxMode.MultiLine;
else
tx1.TextMode = TextBoxMode.SingleLine;
tx1.EnableViewState = true;
tx1.Attributes.Add("onKeyUp", "return autoCheckalpn(this);");
tx1.Attributes.Add("onBlur", "return autoCheckalpnC(this);");
if(width < 50)
tx1.Width = 50;
else
tx1.Width = width;
this.Controls.Add(new LiteralControl("<SCRIPT LANGUAGE='JavaScript'>"));
this.Controls.Add(new LiteralControl("var isNN = (navigator.appName.indexOf('Netscape')!=-1);"));
this.Controls.Add(new LiteralControl("</SCRIPT>"));
this.Controls.Add(tx1);
text = tx1.Text;
}
if(controltype == "Phone")
{
tx1.ID = "tx1";
tx1.MaxLength = 3;
tx1.EnableViewState = true;
tx1.Attributes.Add("onKeyUp", "return autoTabP(this, 3, event);");
tx1.Attributes.Add("onBlur", "return autoChecknumC(this);");
tx1.Width = 30;
if(cssclass!=null && cssclass.Length !=0)
tx1.CssClass = cssclass;
tx2.ID = "tx2";
tx2.MaxLength = 3;
tx2.Attributes.Add("onKeyUp", "return autoTabP(this, 3, event);");
tx2.Attributes.Add("onBlur", "return autoChecknumC(this);");
tx2.Width = 30;
if(cssclass!=null && cssclass.Length !=0)
tx2.CssClass = cssclass;
tx3.ID = "tx3";
tx3.MaxLength = 4;
tx3.Attributes.Add("onKeyUp", "return autoTabP(this, 4, event);");
tx3.Attributes.Add("onBlur", "return autoChecknumC(this);");
tx3.Width = 35;
if(cssclass!=null && cssclass.Length !=0)
tx3.CssClass = cssclass;
this.Controls.Add(tx1);
this.Controls.Add(new LiteralControl(" "));
this.Controls.Add(tx2);
this.Controls.Add(new LiteralControl(" "));
this.Controls.Add(tx3);
this.Controls.Add(new LiteralControl(" "));
if(extnneeded == boolean.True)
{
tx4.ID = "tx4";
tx4.MaxLength = 4;
tx4.Attributes.Add("onKeyUp", "return autoTabP(this, 4, event);");
tx4.Attributes.Add("onBlur", "return autoChecknumC(this);");
tx4.Width = 35;
if(cssclass!=null && cssclass.Length !=0)
tx4.CssClass = cssclass;
this.Controls.Add(tx4);
}
if(extnneeded == boolean.True)
text = tx1.Text+"-"+tx2.Text+"-"+tx3.Text+"-"+tx4.Text;
else
text = tx1.Text+"-"+tx2.Text+"-"+tx3.Text;
}
if(controltype == "SSN")
{
tx1.ID = "tx1";
tx1.MaxLength = 3;
tx1.EnableViewState = true;
tx1.Attributes.Add("onKeyUp", "return autoTabSSN(this, 3, event);");
tx1.Attributes.Add("onBlur", "return autoCheckSSNC(this);");
tx1.Width = 30;
if(cssclass!=null && cssclass.Length !=0)
tx1.CssClass = cssclass;
tx2.ID = "tx2";
tx2.MaxLength = 2;
tx2.Attributes.Add("onKeyUp", "return autoTabSSN(this, 2, event);");
tx2.Attributes.Add("onBlur", "return autoCheckSSNC(this);");
tx2.Width = 25;
if(cssclass!=null && cssclass.Length !=0)
tx2.CssClass = cssclass;
tx3.ID = "tx3";
tx3.MaxLength = 4;
tx3.Attributes.Add("onKeyUp", "return autoTabSSN(this, 4, event);");
tx3.Attributes.Add("onBlur", "return autoCheckSSNC(this);");
tx3.Width = 35;
if(cssclass!=null && cssclass.Length !=0)
tx3.CssClass = cssclass;
this.Controls.Add(tx1);
this.Controls.Add(new LiteralControl("-"));
this.Controls.Add(tx2);
this.Controls.Add(new LiteralControl("-"));
this.Controls.Add(tx3);
this.Controls.Add(new LiteralControl(" "));
text = tx1.Text+"-"+tx2.Text+"-"+tx3.Text;
}
if(controltype == "Credit Card")
{
hdnselcardtype = new HtmlInputHidden();
hdnselcardtype.ID = "hdnselcardtype";
this.Controls.Add(hdnselcardtype);
ListItem li;
dd1.ID = "dd1";
li = new ListItem("--Select Card Type--","0");
dd1.Items.Add(li);
li = new ListItem("Visa","Visa");
dd1.Items.Add(li);
li = new ListItem("MasterCard","MasterCard");
dd1.Items.Add(li);
li = new ListItem("American Express","AmEx");
dd1.Items.Add(li);
li = new ListItem("CarteBlanche","CarteBlanche");
dd1.Items.Add(li);
li = new ListItem("Diners Club","DinersClub");
dd1.Items.Add(li);
li = new ListItem("Discover","Discover");
dd1.Items.Add(li);
li = new ListItem("enRoute","Enroute");
dd1.Items.Add(li);
li = new ListItem("JCB","JCB");
dd1.Items.Add(li);
if(cssclass!=null && cssclass.Length !=0)
dd1.CssClass = cssclass;
dd1.AutoPostBack = true;
//if(System.Web.HttpContext.Current.Session[this.ClientID]!=null)
//Createcreditcard(System.Web.HttpContext.Current.Session[this.ClientID].ToString());
dd1.SelectedIndexChanged+=new EventHandler(dd1_SelectedIndexChanged);
this.Controls.Add(dd1);
//else
//this.Controls.Add(dd1);
//Createcreditcard(hdnselcardtype.Value);
}
base.CreateChildControls ();
}
private bool IsAlpha(String str)
{
Regex objregex=new Regex("[^a-zA-Z\\s]");
return !objregex.IsMatch(str);
}
private bool IsAlphaNumeric(String str)
{
Regex objregex=new Regex("[^a-zA-Z0-9]");
return !objregex.IsMatch(str);
}
private bool IsNumber(String str)
{
Regex objregex=new Regex("[^0-9]");
return !objregex.IsMatch(str);
}
private bool IsMoney(String str)
{
Regex objregex=new Regex("[^0-9\\.]");
return !objregex.IsMatch(str);
}
private void dd1_SelectedIndexChanged(object sender, System.EventArgs e)
{
Createcreditcard(dd1.SelectedValue);
hdnselcardtype.Value = dd1.SelectedValue;
//System.Web.HttpContext.Current.Session[this.ClientID]=dd1.SelectedValue;
}
private void Createcreditcard(string strcardtype)
{
if(strcardtype == "Visa" || strcardtype == "MasterCard" || strcardtype == "Discover" || strcardtype == "JCB")
{
tx1.ID = "tx1";
tx1.MaxLength = 4;
tx1.EnableViewState = true;
tx1.Attributes.Add("onKeyUp", "return autoTabC(this, 4, event);");
tx1.Attributes.Add("onBlur", "return autoChecknumC(this);");
tx1.Width = 35;
if(cssclass!=null && cssclass.Length !=0)
tx1.CssClass = cssclass;
tx2.ID = "tx2";
tx2.MaxLength = 4;
tx2.Attributes.Add("onKeyUp", "return autoTabC(this, 4, event);");
tx2.Attributes.Add("onBlur", "return autoChecknumC(this);");
tx2.Width = 35;
if(cssclass!=null && cssclass.Length !=0)
tx2.CssClass = cssclass;
tx3.ID = "tx3";
tx3.MaxLength = 4;
tx3.Attributes.Add("onKeyUp", "return autoTabC(this, 4, event);");
tx3.Attributes.Add("onBlur", "return autoChecknumC(this);");
tx3.Width = 35;
if(cssclass!=null && cssclass.Length !=0)
tx3.CssClass = cssclass;
tx4.ID = "tx4";
tx4.MaxLength = 4;
tx4.Attributes.Add("onBlur", "return autoTabC(this, 4, event);");
//tx4.Attributes.Add("onBlur", "return autoTabP(this);");
tx4.Width = 35;
if(cssclass!=null && cssclass.Length !=0)
tx3.CssClass = cssclass;
this.Controls.Add(tx1);
this.Controls.Add(new LiteralControl("-"));
this.Controls.Add(tx2);
this.Controls.Add(new LiteralControl("-"));
this.Controls.Add(tx3);
this.Controls.Add(new LiteralControl("-"));
this.Controls.Add(tx4);
this.Controls.Add(new LiteralControl(" "));
text = tx1.Text+tx2.Text+tx3.Text+tx4.Text;
}
if(strcardtype == "AmEx" || strcardtype == "Enroute")
{
tx1.ID = "tx1";
tx1.MaxLength = 4;
tx1.EnableViewState = true;
tx1.Attributes.Add("onKeyUp", "return autoTabC(this, 4, event);");
tx1.Attributes.Add("onBlur", "return autoChecknumC(this);");
tx1.Width = 35;
if(cssclass!=null && cssclass.Length !=0)
tx1.CssClass = cssclass;
tx2.ID = "tx2";
tx2.MaxLength = 6;
tx2.Attributes.Add("onKeyUp", "return autoTabC(this, 6, event);");
tx2.Attributes.Add("onBlur", "return autoChecknumC(this);");
tx2.Width = 50;
if(cssclass!=null && cssclass.Length !=0)
tx2.CssClass = cssclass;
tx3.ID = "tx3";
tx3.MaxLength = 5;
tx3.Attributes.Add("onBlur", "return autoTabC(this, 5, event);");
//tx3.Attributes.Add("onBlur", "return autoChecknumC(this);");
tx3.Width = 40;
if(cssclass!=null && cssclass.Length !=0)
tx3.CssClass = cssclass;
this.Controls.Add(tx1);
this.Controls.Add(new LiteralControl("-"));
this.Controls.Add(tx2);
this.Controls.Add(new LiteralControl("-"));
this.Controls.Add(tx3);
this.Controls.Add(new LiteralControl(" "));
text = tx1.Text+tx2.Text+tx3.Text;
}
if(strcardtype == "CarteBlanche" || strcardtype == "DinersClub")
{
tx1.ID = "tx1";
tx1.MaxLength = 4;
tx1.EnableViewState = true;
tx1.Attributes.Add("onKeyUp", "return autoTabP(this, 4, event);");
tx1.Attributes.Add("onBlur", "return autoChecknumC(this);");
tx1.Width = 35;
if(cssclass!=null && cssclass.Length !=0)
tx1.CssClass = cssclass;
tx2.ID = "tx2";
tx2.MaxLength = 6;
tx2.Attributes.Add("onKeyUp", "return autoTabP(this, 6, event);");
tx2.Attributes.Add("onBlur", "return autoChecknumC(this);");
tx2.Width = 50;
if(cssclass!=null && cssclass.Length !=0)
tx2.CssClass = cssclass;
tx3.ID = "tx3";
tx3.MaxLength = 4;
tx3.Attributes.Add("onBlur", "return autoTabP(this, 4, event);");
//tx3.Attributes.Add("onBlur", "return autoChecknumC(this);");
tx3.Width = 35;
if(cssclass!=null && cssclass.Length !=0)
tx3.CssClass = cssclass;
this.Controls.Add(tx1);
this.Controls.Add(new LiteralControl("-"));
this.Controls.Add(tx2);
this.Controls.Add(new LiteralControl("-"));
this.Controls.Add(tx3);
this.Controls.Add(new LiteralControl(" "));
text = tx1.Text+tx2.Text+tx3.Text;
}
}
}
[ComVisible(false)]
public class ClasstypeConverter : System.ComponentModel.TypeConverter
{
private ArrayList values;
public ClasstypeConverter()
{
values = new ArrayList(new string[] { "Class A","Class B" , "Class C", "Class D", "Class E" });
}
public override bool GetStandardValuesSupported(System.ComponentModel.ITypeDescriptorContext context)
{
return true;
}
public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(System.ComponentModel.ITypeDescriptorContext context)
{
StandardValuesCollection svc = new StandardValuesCollection(values);
return svc;
}
public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
{
if( sourceType == typeof(string) )
return true;
else
return base.CanConvertFrom(context, sourceType);
}
public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
{
if( value.GetType() == typeof(string) )
{
string newVal = (string)value;
if( !values.Contains(newVal) )
{
values.Add(newVal);
values.Sort();
}
return newVal;
}
else
return base.ConvertFrom(context, culture, value);
}
}
public class ControltypeConverter : System.ComponentModel.TypeConverter
{
private ArrayList values;
public ControltypeConverter()
{
values = new ArrayList(new string[] { "Alpha Only", "Numeric Only" , "Alphanumeric", "Phone", "SSN", "IP Address", "Credit Card", "Money" });
}
public override bool GetStandardValuesSupported(System.ComponentModel.ITypeDescriptorContext context)
{
return true;
}
public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(System.ComponentModel.ITypeDescriptorContext context)
{
StandardValuesCollection svc = new StandardValuesCollection(values);
return svc;
}
public override bool CanConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Type sourceType)
{
if( sourceType == typeof(string) )
return true;
else
return base.CanConvertFrom(context, sourceType);
}
public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
{
if( value.GetType() == typeof(string) )
{
string newVal = (string)value;
if( !values.Contains(newVal) )
{
values.Add(newVal);
values.Sort();
}
return newVal;
}
else
return base.ConvertFrom(context, culture, value);
}
}
}