Click here to Skip to main content
11,648,094 members (64,349 online)
Click here to Skip to main content

Xtended TextBox

, 26 Jul 2006 CPOL 104.5K 2.4K 62
Rate this:
Please Sign up or sign in to vote.
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Venkat Eswaran
Web Developer TCS
India India
No Biography provided

You may also be interested in...

Comments and Discussions

 
QuestionThanks !!!! a lottt !!!! Pin
OrlandoMorales17-Apr-12 7:53
memberOrlandoMorales17-Apr-12 7:53 
GeneralXtended TextBox Pin
scholekar21-Mar-11 2:40
memberscholekar21-Mar-11 2:40 
Hi Venkat,

Very nice article..... Great Work Venkat.... Keep it up.
QuestionGet IP Address value in Javascript Pin
Pramod Ingle18-May-09 18:57
memberPramod Ingle18-May-09 18:57 
Generalon Windows form.. Pin
MrAntonD17-Sep-08 23:14
memberMrAntonD17-Sep-08 23:14 
QuestionHow to make a custom WYSWYG TextBox inherited from Usercontrol which can capture Unicode inputting? Pin
Davidwu20-Jun-08 9:22
memberDavidwu20-Jun-08 9:22 
QuestionHow to allow only numeric in textbox asp.net Pin
dilip.dil8511-Jun-08 7:49
memberdilip.dil8511-Jun-08 7:49 
GeneralAwesome job Venkat Pin
hacher7520-May-08 13:09
memberhacher7520-May-08 13:09 
Generalrequired field validator Pin
rufix1-May-07 3:25
memberrufix1-May-07 3:25 
QuestionDisable Control Pin
Hsien-Wu9-Jan-07 6:21
memberHsien-Wu9-Jan-07 6:21 
AnswerRe: Disable Control Pin
Venkat Eswaran13-Jan-07 16:58
memberVenkat Eswaran13-Jan-07 16:58 
QuestionCould I use with Visual Studio 2005 ? Pin
waimoehtun18-Dec-06 0:51
memberwaimoehtun18-Dec-06 0:51 
Generalnice control, but Pin
Josema12-Oct-06 12:28
memberJosema12-Oct-06 12:28 
GeneralRe: nice control, but Pin
Venkat Eswaran13-Oct-06 6:07
memberVenkat Eswaran13-Oct-06 6:07 
GeneralSSN Serial number does not allow leading Zero Pin
hboatz28-Sep-06 4:16
memberhboatz28-Sep-06 4:16 
GeneralMake Phone Number Required Pin
creese16-Aug-06 18:39
membercreese16-Aug-06 18:39 
GeneralRe: Make Phone Number Required Pin
Venkat Eswaran17-Aug-06 5:53
memberVenkat Eswaran17-Aug-06 5:53 
Questionregarding Xtended Textbox Pin
srikant_net31-Jul-06 23:22
membersrikant_net31-Jul-06 23:22 
AnswerRe: regarding Xtended Textbox [modified] Pin
Venkat Eswaran1-Aug-06 1:14
memberVenkat Eswaran1-Aug-06 1:14 
GeneralGr8 One Pin
nvenkat31-Jul-06 2:19
membernvenkat31-Jul-06 2:19 
Generalfail in add to toolbox Pin
Antonino Ferrando25-Jul-06 4:30
memberAntonino Ferrando25-Jul-06 4:30 
AnswerRe: fail in add to toolbox Pin
Venkat Eswaran25-Jul-06 5:59
memberVenkat Eswaran25-Jul-06 5:59 
Questionwhy the rate is so low? Pin
qiuyl24-Jul-06 17:13
memberqiuyl24-Jul-06 17:13 
Generalgood one Pin
bharathkumar19-Jul-06 2:43
memberbharathkumar19-Jul-06 2:43 
GeneralRe: good one Pin
BigJim6127-Jul-06 3:07
memberBigJim6127-Jul-06 3:07 
GeneralRe: good one Pin
Venkat Eswaran27-Jul-06 5:46
memberVenkat Eswaran27-Jul-06 5:46 
GeneralFile missing Pin
D.R.O.17-Jul-06 4:45
memberD.R.O.17-Jul-06 4:45 
GeneralRe: File missing Pin
Venkat Eswaran17-Jul-06 5:48
memberVenkat Eswaran17-Jul-06 5:48 
GeneralRe: File missing Pin
dozen32110-Sep-09 10:16
memberdozen32110-Sep-09 10:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150804.4 | Last Updated 26 Jul 2006
Article Copyright 2006 by Venkat Eswaran
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid