Custom Validator not working with RadMaskedTextBox

1 Answer 60 Views
TextBox
Chhavi
Top achievements
Rank 1
Chhavi asked on 27 Sep 2022, 10:04 PM

I have set  a java script method

validatePhone

to be called for customeValidator against any change on a RadMaskedTextBox.  But its never gets called.

Can you please help whats wrong here?

 

<td>
<telerik:RadMaskedTextBox ID="sNumberPhoneMasked" runat="server" SelectionOnFocus="CaretToBeginning"
Text='<%# SafeEval(Container, "DataItem.Test") %>' ValidationGroup="PhoneValidationGroup1" ></telerik:RadMaskedTextBox>
<asp:Label ID="sNumberPhoneMaskedValidationIndicator" runat="server" class="WizardValidationRequired_Person vAdjustment" >*</asp:Label>


<asp:CustomValidator runat="server" ID="sNumberPhoneMaskedValidator" ValidationGroup="PhoneValidationGroup1" ErrorMessage="Phone Number is required."
SetFocusOnError="true" ControlToValidate="sNumberPhoneMasked" ClientValidationFunction="validatePhone"></asp:CustomValidator>
<asp:ValidatorCalloutExtender ID="sNumberPhoneMaskedPopupValidator" runat="server"
TargetControlID="sNumberPhoneMaskedValidator" Width="200px" />

</td>

 

<td align="right" colspan="2">
<asp:Button ID="sPhoneGridEditFormSubmit" CssClass="button-blue" Text='<%# (Container is GridEditFormInsertItem) ? "Add" : "Update" %>'
runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "Add" : "Update" %>' ValidationGroup="PhoneValidationGroup1"
CausesValidation="True"></asp:Button>&nbsp;
<asp:Button ID="sCancel" CssClass="button-blue" Text="Discard" runat="server" CausesValidation="False"
CommandName="Cancel"></asp:Button>
</td>

 

<script type="text/javascript">
function validatePhone(Source, args) {
debugger;
alert('test');
args.IsValid=false;

}
</script>

1 Answer, 1 is accepted

Sort by
0
Rumen
Telerik team
answered on 30 Sep 2022, 11:25 AM

Hi Chhavi,

Please refer to this StackOverflow post - https://stackoverflow.com/questions/55538198/telerik-control-rasmaskedtextbox-is-not-showing-error-message

Here is also an example:

ASPX

        <asp:CustomValidator ID="CustomValidator1" runat="server" ValidationGroup="PhoneValidationGroup1"
            ClientValidationFunction="validatePhone"
            ErrorMessage="Phone Number is required."
            ControlToValidate="sNumberPhoneMasked">*</asp:CustomValidator>


        <asp:Button ID="sPhoneGridEditFormSubmit" CssClass="button-blue" Text='Add'
            runat="server" ValidationGroup="PhoneValidationGroup1"
            CausesValidation="True"></asp:Button>&nbsp;
 

        <script type="text/javascript">
            function validatePhone(Source, args) {
                debugger;
                alert('test');
                args.IsValid = false;

            }
        </script>

web.config

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

Regards,
Rumen
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
TextBox
Asked by
Chhavi
Top achievements
Rank 1
Answers by
Rumen
Telerik team
Share this question
or