This is a migrated thread and some comments may be shown as answers.

Client side validation on RadMaskedTextbox

3 Answers 239 Views
MaskedTextBox
This is a migrated thread and some comments may be shown as answers.
Fit2Page
Top achievements
Rank 2
Iron
Iron
Iron
Fit2Page asked on 22 Dec 2020, 08:28 AM

Hi,

 

When I try to use client side validation on RadMaskedTextbox as follows, the validation still takes place after a postback. is this a bug?

I try to follow your demo https://demos.telerik.com/aspnet-ajax/textbox/functionality/validation/defaultvb.aspx

 

    <asp:TextBox ID="batch" runat="server" Width="60%"></asp:TextBox>
     <asp:RequiredFieldValidator ErrorMessage="Mandatory" ValidationGroup="Contact" Enabled="True" id="batchReq" ControlToValidate="batch" CssClass="text-danger small" display="dynamic" runat=server />
    <br />



      <telerik:RadMaskedTextBox RenderMode="Lightweight" EnableEmbeddedSkins="false" Skin="MetroTouchNeutral" ValidationGroup="Contact" ID="rmt_tijd" visible="true" runat="server" Mask="<0..24>:<0..59>" Width="30%"></telerik:RadMaskedTextBox>




                            <asp:RequiredFieldValidator EnableClientScript="true" ErrorMessage="Mandatory" ValidationGroup="Contact" Enabled="true" InitialValue="00:00"  id="RequiredFieldValidator3" ControlToValidate="rmt_tijd" CssClass="text-danger small" display="dynamic" runat=server />

    <br />
    <asp:Button ID="Button1" runat="server" Text="Button" ValidationGroup="Contact"  />

 

 

Thanks for your help, stay safe

Marc

3 Answers, 1 is accepted

Sort by
0
Peter Milchev
Telerik team
answered on 22 Dec 2020, 08:41 AM

Hello Marc,

If the client-side validation is failing and a postback is triggered while your project is set to .NET 4.5+, then most probably you would need to disable the default unobtrusive validation by placing the following entry in the appSettings of your web.config:

Regards,
Peter Milchev
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/.

0
Fit2Page
Top achievements
Rank 2
Iron
Iron
Iron
answered on 22 Dec 2020, 09:04 AM

TargetFramework = 4.6.1 and ValidationSettings:UnobtrusiveValidationMode is already set.

 

Still no client-side validation...

 

Marc

0
Peter Milchev
Telerik team
answered on 24 Dec 2020, 12:54 PM

Hello Marc,

I have inspected the validation logic of the RequiredFieldValidator and the value of the input is actually trimmed to "0:0" which is why the client-side validation was not triggered. If you set the InitialValue to 0:0, then the client-side validation will work.

That is because the ValidatorGetValue function of the MS AJAX framework is overwritten in order to take into consideration the RadMaskedTextBox:

  • if (typeof (window.ValidatorGetValue) == "function" && typeof (window.ValidatorGetValue_Original) == "undefined") {
        window.ValidatorGetValue_Original = window.ValidatorGetValue;
        window.ValidatorGetValue = function (b) {
            var a = document.getElementById(b);
            if (typeof (a.RadInputValidationValue) == "string") {
                if (a.RadInputLastSetTextBoxValue == a.value) {
                    return a.RadInputValidationValue;
                } else {
                    return a.value;
                }
            } else {
                return window.ValidatorGetValue_Original(b);
            }
        };
    }

Let me know how that works for you.

Regards,
Peter Milchev
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
MaskedTextBox
Asked by
Fit2Page
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Peter Milchev
Telerik team
Fit2Page
Top achievements
Rank 2
Iron
Iron
Iron
Share this question
or