Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Xtended TextBox

0.00/5 (No votes)
26 Jul 2006 2  
A Masked TextBox for ASP.NET

Sample Image - Extended_TextBox.jpg

Introduction

Whether it is a web application or a windows application textbox is the most widely used control. The masked textbox is
available for windows forms. But we dont have one for ASP.NET. So I decided to write one for ASP.NET.
Using Extended TextBox control will save a lot of time for developers in writing code for validation.

This control uses the credit card validation script writen by John Gardner

Using the code

The control is created as WebCustomControl by extending from System.Web.UI.TemplateControl. By using this control
one can do validation on controls without writing any code. The control is built with intelligence such that, you can just select the controltype. Ex. Alpha only, Numeric Only, Alphanumeric, IP Address, Phone, Social Security Number. If you set
the controltype to SSN then the textbox is masked for Social Security Number. It has the following properties.
  • ControlType - Type of control to be rendered
  • ClassType - IP Address class type (applicable only for IP Address textbox)
  • ExtnNeeded - Telephone number extension needed (applicable only for Telephone)
  • MaxLength - The maximum number of characters that can be entered (not Applicable for IP Address, Telephone, SSN)
  • Width - Width of the control (not Applicable for IP Address, Telephone, SSN)
  • TextMode - The behaviour of textbox (not applicable for IP Address, Telephone, SSN)
  • CssClass - CSS Class name applied to the control
  • Text - Gets and Sets the value in textbox
  • SelectedCard - Gets the selected card

The control types :

Alpha only: On selecting controltype as Alpha only, it will allow anly alpha characters in the textbox.

Numeric Only: On selecting controltype as Numeric Only, it will allow only number in the textbox.

Alphanumeric: On selecting controltype as Alphanumeric, it will allow both number and alphabets in the textbox.

IP Address: On selecting controltype as IP Address, it will allow only IP Address with fixed '.' as in windows. It will allow only numbers to key in. For further validation of IP address Classtype is selected Ex: Class A, Class B... With the respect
to the class type the validation are done. So the developer doesn't need to write code for validations and autofocus.

Phone: On selecting controltype as Phone, it will allow only phone numbers with (NPA-NXX-XXXX). It will allow only
numbers to key in. To enable extentions set ExtnNeeded to true. This can also be turned off.

Social Security Number: On selecting controltype as SSN, it will allow only SSN (Area code - Group number - Serial Number).

Credit Card: On selecting card type and controltype as Credit Card, it will allow only valid Credit card numbers.

Money: On selecting card type and controltype as Money, it will allow only number or decimal values with currency symbol on the right.

Steps to use the control

1. Right click the mouse in the ToolBox, and select Add/Remove Items to open customize Toolbox dialog.
2. Select the tab .NET framework component.
3. Browse for your DLL, check it, then click Ok.
4. Drag the control from the ToolBox into the form and set the properties to the control.
5. Copy the Masked.js to the root folder of the web application.

Designer Extended textbox

For example :

<cc3:maskedtextbox id="Maskedtextbox11" runat="server" ControlType="IP Address" ClassType="Class A">
                                                </cc3:maskedtextbox>
<cc3:maskedtextbox id="Maskedtextbox10" runat="server" ControlType="SSN"> </cc3:maskedtextbox>
<cc3:maskedtextbox id="Maskedtextbox7" runat="server" ControlType="Phone" ExtnNeeded="True">
                                                </cc3:maskedtextbox>

Limitations

The Credit card control can be used only with EnableViewstate = false.

 

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here