Telerik控件RasMaskedTextBox没有显示错误消息

时间:2019-04-05 14:55:42

标签: c# telerik

我正在使用CustomValidator来处理Telerik RadMaskedTextbox。问题是,如果我不输入任何值,则不会显示错误消息。

<telerik:RadMaskedTextBox ID="RadMaskedTextBox3" runat="server"
                                        Width="150"
                                        Mask="(###) ###-####  ext. #####">
                                    </telerik:RadMaskedTextBox>
 <asp:CustomValidator ID="CustomValidator4" runat="server"                                        
                                        ErrorMessage="*"
                                        Display="Dynamic"
                                        CssClass="error1"
                                        Enabled="false"
                                        ToolTip="At least one Phone no: needs to be filled in."
                                        ValidateEmptyText="true"
                                        EnableClientScript="true"
                                        OnServerValidate="CustomValidator_ServerValidate"
                                        SetFocusOnError ="true"                                             
                                        ValidationGroup="CarrierBaseInformation1">
                                    </asp:CustomValidator>

2 个答案:

答案 0 :(得分:0)

以下是实现目标的示例:

在Web.config中设置

<appSettings>
  <add key="ValidationSettings:UnobtrusiveValidationMode" value="None"/>

在aspx

<telerik:RadMaskedTextBox Mask="(###) ###-####  ext. #####" RenderMode="Lightweight" ID="RadMaskedTextBox1" runat="server" EmptyMessage="Enter username"></telerik:RadMaskedTextBox>

<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" Text="*" ControlToValidate="RadMaskedTextBox1"></asp:RequiredFieldValidator>
<asp:Button ID="Button1" runat="server" Text="PostBack" />

答案 1 :(得分:0)

这是CustomValidator的另一个示例:

<asp:CustomValidator ID="CustomValidator1" runat="server"
    ClientValidationFunction="CheckLength"
    ErrorMessage="Phone\Fax numbers must be 7 or 9 digits"
    ControlToValidate="txtTollFree">*</asp:CustomValidator>
<script>
function CheckLength(source, args)  
{  
    if (args.Value.length == 10 || args.Value.length == 13)  
    {  
        args.IsValid = true;  
    }else{  
        args.IsValid = false;  
    }  
} 
</script>