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

Show error message inside Textbox

3 Answers 263 Views
Input
This is a migrated thread and some comments may be shown as answers.
Saira
Top achievements
Rank 1
Saira asked on 12 Mar 2013, 07:49 AM
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

3 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 12 Mar 2013, 08:40 AM
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.
0
Rob Ainscough
Top achievements
Rank 1
answered on 03 Oct 2018, 09:07 PM

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.

0
Marin Bratanov
Telerik team
answered on 04 Oct 2018, 11:11 AM
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.
Tags
Input
Asked by
Saira
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Rob Ainscough
Top achievements
Rank 1
Marin Bratanov
Telerik team
Share this question
or