JS:
function HandleMaskError(sender, eventArgs) {
// on masked text box, get_newValue() returns the problem value
alert("Invalid value: " + eventArgs.get_newValue());
// get_currentPart() returns the part that failed to match
var part = eventArgs.get_currentPart();
if (part) {
// set the cursor on the problem part
sender.set_cursorPosition(part.offset);
}
// we did not correct the error, so cancel the edit
eventArgs.set_cancel(true);
}
function HandleNumericError(sender, eventArgs) {
switch (eventArgs.get_reason()) {
case 1: // Parsing error --no invalid value available
alert("Invalid character!");
break;
case 2: // Out of range
alert("Value out of range: " + eventArgs.get_inputText());
break;
}
// we did not correct the error, so cancel the edit
eventArgs.set_cancel(true);
// return focus to the numeric text box
sender.focus();
}
function HandleDateError(sender, eventArgs) {
switch (eventArgs.get_reason()) {
case 1: // Parsing error
alert("Value could not be parsed: " + eventArgs.get_inputText());
break;
case 2: // Out of range
alert("Value out of range: " + eventArgs.get_inputText());
break;
}
// we did not correct the error, so cancel the edit
eventArgs.set_cancel(true);
// return focus to the date input control
sender.focus();
}
ASPX:
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<telerik:RadMaskedTextBox ID="RadMaskedTextBox1" Runat="server"
EmptyMessage="-Enter SSN -" HideOnBlur="True" Mask="###-##-####">
<ClientEvents OnError="HandleMaskError" />
</telerik:RadMaskedTextBox>
<br />
<telerik:RadNumericTextBox ID="RadNumericTextBox1" Runat="server"
Culture="English (United States)"
EmptyMessage="-Enter cost below $5.00 -"
MaxValue="5" MinValue="0.01" Type="Currency" Width="125px">
<ClientEvents OnError="HandleNumericError" />
RadControls for ASP.NET AJAX
63 RadControls for ASP.NET AJAX
You can enhance the functionality of RadTextBox by using it in combination with other ASP.NET controls.
Using ASP.NET validators with input RadControls
It is easy to use the input RadControls with ASP.NET validators: simply set the ControlToValidateproperty of
the validator to the text box, masked text box, numeric text box, or date input control that you want to
validate.
You can assign the input controls on your Web page to different validation groups so that the validators check
them at different times. All you need do is set the ValidationGroupproperty of the validator to match the
ValidationGroupproperty of the control that initiates the validation.
You can even use an input control to initiate validation. Just set the CausesValidationproperty to true, and it
will initiate a validation every time its value changes.
The following example illustrates using validators with RadTextBox, although you can use them with any of the
input controls. It demonstrates both the use of validation groups and the way an input control can trigger
validation.
The form uses three validation groups: "LoginGroup", "SignUpGroup", and "PWGroup":
The "LoginGroup" validation group is assigned to the two validators in the left-hand panel, and to the
button in that panel which triggers validation on postback. Note that no special settings are required on
the text boxes; they are validated simply because of the ControlToValidateproperty of the corresponding
</telerik:RadNumericTextBox>
<br />
<telerik:RadDateInput ID="RadDateInput1" Runat="server"
EmptyMessage="-Enter date in 1990's-"
MaxDate="1999-12-31" MinDate="1990-01-01">
<ClientEvents OnError="HandleDateError" />
</telerik:RadDateInput>
</div>
</form>