RadInput Error handling

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>


 


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值