Show error message inside Textbox

4 posts, 1 answers
  1. Saira
    Saira avatar
    24 posts
    Member since:
    Feb 2013

    Posted 12 Mar 2013 Link to this post

    Hello,

    I am developing a web site to target mobile devices and So to save space i want to display error messages inside the Radtextbox if validation fails. Is this possible?

    Thank you,
    Saira
  2. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 12 Mar 2013 Link to this post

    Hello Saira,

    Yes, its possible to display the error messgae inside the RadTextBox. Please have a look into the following code I tried.

    ASPX:
    <telerik:RadTextBox ID="RadTextBox1" runat="server" EmptyMessage="Enter username">
    </telerik:RadTextBox>
    <telerik:RadTextBox ID="RadTextBox2" runat="server" EmptyMessage="Enter password">
    </telerik:RadTextBox>
    <asp:Button ID="Button1" runat="server" Text="PostBack" />
    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" Text="username is required" ControlToValidate="RadTextBox1"
        Style="display: none;"></asp:RequiredFieldValidator>
    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" Text="password is required" ControlToValidate="RadTextBox2"
        Style="display: none;"></asp:RequiredFieldValidator>

    JavaScript:
    <script type="text/javascript">
      ValidationSummaryOnSubmit = function (validationGroup) {
          for (var i = 0; i < Page_Validators.length; i++)
              if (!Page_Validators[i].isvalid) {
                  var textbox = $find(Page_Validators[i].controltovalidate);
                  if (textbox) {
                      textbox.set_textBoxValue(Page_Validators[i].textContent);
                      textbox._invalidate();
                      textbox.updateCssClass();
                  }
              }
        }
     </script>

    Thanks,
    Shinu.
  3. Rob Ainscough
    Rob Ainscough avatar
    262 posts
    Member since:
    Jan 2010

    Posted 03 Oct 2018 in reply to Shinu Link to this post

    I know this is old, but this code doesn't appear to work, nothing happens.   I also tried this code here: https://docs.telerik.com/devtools/aspnet-ajax/controls/textbox/features/validation  and same result, nothing happens.

    Is there something else not mentioned that needs to be included for this to work?

    Cheers, Rob.

  4. Marin Bratanov
    Admin
    Marin Bratanov avatar
    5067 posts

    Posted 04 Oct 2018 Link to this post

    Hello Rob,

    I created a KB article for you with an improved version of the code: https://www.telerik.com/support/kb/aspnet-ajax/textbox/details/how-to-display-errormessage-inside-radtextbox. I suspect that your original issue stems from the Unobtrusive validation that needs to be disabled for this hack to have a chance.


    Regards,
    Marin Bratanov
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top