Client side validation on RadMaskedTextbox

4 posts, 0 answers
  1. Fit2Page
    Fit2Page avatar
    468 posts
    Member since:
    Feb 2007

    Posted 22 Dec 2020 Link to this post

    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

  2. Peter Milchev
    Admin
    Peter Milchev avatar
    911 posts

    Posted 22 Dec 2020 Link to this post

    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/.

  3. Fit2Page
    Fit2Page avatar
    468 posts
    Member since:
    Feb 2007

    Posted 22 Dec 2020 in reply to Peter Milchev Link to this post

    TargetFramework = 4.6.1 and ValidationSettings:UnobtrusiveValidationMode is already set.

     

    Still no client-side validation...

     

    Marc

  4. Peter Milchev
    Admin
    Peter Milchev avatar
    911 posts

    Posted 24 Dec 2020 Link to this post

    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/.

Back to Top