ASP.NET Pack Programmer's Guide
MaskTextBox

The MaskTextBox control represents a text input control that constrains the user input to a specified mask. Use the MaskTextBox for data with fixed length and defined format, such as phone numbers, SSN-s, zip codes, etc. 

Server side

Specifying the mask

Use the Mask property to set the input mask for the control. You can use the following symbols to specify the allowed set of characters for any position:

Character

Description

0

Indicates that the specified position can only hold a digit.

9

Indicates that the specified position can hold a digit or it could be empty.

L

Indicates that the specified position can only hold a letter.

l

Indicates that the specified position can hold a letter or it could be empty.

A

Indicates that the specified position can hold either a digit or a letter.

a

Indicates that the specified position can hold either a digit or a letter or it could be empty.

?

Indicates that the specified position can hold any character.

\

Escape char. Indicates that the next character in the mask should be treated as a literal.

any other

Any other symbols are displayed as literals.

Getting and setting the control's text

Use the MaskTextBox.Text or MaskTextBox.Value properties to get or set the control's text.

Customizing the control

Use the PromptChar property to specify the character used for a blank position in control's input. By setting the AllowEmptyInput property you can define whether or not empty string values are considered valid for the control.

Adjust the interaction with the control by setting the SubmitOnEnter and AutoPostBack properties according to your needs.

By setting the EmptyText property you can display a hint to the user, and by setting the Label and LabelPosition properties you can specify a caption for the control.

Events

The following events are exposed by the MaskTextBox class.

Event

Event arguments

Description

ValueChanged

ValueChangedEventArgs<String>

Raised when the control's value has changed.

Client side

Getting a reference to the control

You can access the control on the client side by its ClientID.

JavaScript  Copy Code

var maskBox = $find("MaskTextBox1");
var maskBox = $find("<%= MaskTextBox1.ClientID %>");

Getting and setting the control's text

Use the get_text and set_text or get_value and set_value methods to get or set the control's text.

JavaScript  Copy Code

maskBox.set_text('(0123)456789');
alert(maskBox.get_value());

Events

The following client-side events are exposed by the MaskTextBox class.

Event

Event arguments

Script property

Description

valueChanging

ValueChangingEventArgs

ValueChangingScript

Raised when a control's value is about to be changed.

valueChanged

ValueChangedEventArgs

ValueChangedScript

Raised when a control's value has changed.

validate

ValueChangingEventArgs

ValidateScript

Raised when the control's value is validating.

valueInvalid

ValueChangedEventArgs

ValueInvalidScript

Raised when the control's input is invalid.

validationStateChanged

ValidationStateChangedEventArgs

ValidationStateChangedScript

Raised when the validation state of the control changes.

controlLoaded

-

ControlLoadedScript

Raised just after the control has finished loading and is ready for interaction.