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

Validation Red border style

5 Answers 145 Views
Input
This is a migrated thread and some comments may be shown as answers.
Arun Kumar
Top achievements
Rank 2
Arun Kumar asked on 28 Nov 2013, 10:09 AM
I am using RadTextBox in SharePoint 2010 visual web part. Also I have RequiredFieldValidator. I want to show red border around RadTextBox on validation error. How do I do that ?

Thanks in advance.

5 Answers, 1 is accepted

Sort by
0
Venelin
Telerik team
answered on 03 Dec 2013, 06:38 AM
Hello,

In order to achieve the desired functionality you can refer to the below resources, where the topic is reviewed in details:

1. RadInput - Validation (documentation)
2. RadInput - Validation (online demo)
2. RadInput - Overview (online demo)

I hope this helps.

Regards,
Venelin
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Arun Kumar
Top achievements
Rank 2
answered on 04 Dec 2013, 11:58 AM
Dear Venelin,

Thanks for your reply.

Validation is working fine but style is not working (Red border is not showing). How do I get this working ?

0
Venelin
Telerik team
answered on 09 Dec 2013, 03:18 PM
Hi Arun,

It would be best if you use a custom validator for this scenario. Here is an article form MSDN: http://msdn.microsoft.com/en-us/library/9eee01cx%28v=vs.85%29.aspx

However if you encounter any difficulties in implementing the desired functionality please do not hesitate to ask.

Regards,
Venelin
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Arun Kumar
Top achievements
Rank 2
answered on 11 Dec 2013, 10:51 AM
Hi Venelin,

I have RequiredFieldValidator, CustomValidator and CompareValidator on the same web part. But none of them showing Red Border around controls. But error message is showing in ValidationSummary. I want to show Red border around invalid controls. Any idea how to achieve this ?
0
Venelin
Telerik team
answered on 14 Dec 2013, 07:24 AM
Hello Arun,

Here I created a very simple example that is actually a modified version of MSDN's example.

ASPX:

<form id="form1" runat="server">
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
        </telerik:RadScriptManager>
        <script runat="server">
 
            void ValidateBtn_OnClick(object sender, EventArgs e)
            {
 
                // Display whether the page passed validation.
                if (Page.IsValid)
                {
 
                    Message.Text = "Page is valid.";
 
                }
 
                else
                {
 
                    Message.Text = "Page is not valid!";
 
                }
 
            }
 
            void ServerValidation(object source, ServerValidateEventArgs args)
            {
 
                try
                {
                    // Test whether the value entered into the text box is even.
                    int i = int.Parse(args.Value);
                    args.IsValid = ((i % 2) == 0);
 
                }
 
                catch (Exception ex)
                {
                    args.IsValid = false;
                }
                 
                if (!args.IsValid)
                {
                    (Text1 as RadTextBox).BorderColor = System.Drawing.Color.FromArgb(255, 0, 0);
                }
 
            }
 
        </script>
        <br />
        <h3>CustomValidator ServerValidate Example</h3>
 
        <asp:Label ID="Message"
            Text="Enter an even number:"
            Font-Names="Verdana"
            Font-Size="10pt"
            runat="server"
            AssociatedControlID="Text1" />
             
        <br />
 
         
        <telerik:RadTextBox runat="server" ID="Text1"></telerik:RadTextBox>
         
 
      <asp:CustomValidator ID="CustomValidator1"
          ControlToValidate="Text1"
          Display="Static"
          ErrorMessage="Not an even number!"
          OnServerValidate="ServerValidation"
          runat="server" />
 
        <br />
 
        <asp:Button ID="Button1"
            Text="Validate"
            OnClick="ValidateBtn_OnClick"
            runat="server" />
        <br />
        <br />
</form>

The code above verifies if the number is even, if it's not, then the form is not valid. This line:
(Text1 as RadTextBox).BorderColor = System.Drawing.Color.FromArgb(255, 0, 0);
actually sets the red border of the text box. Here, it would be best if a CssClass is used instead of BorderColor, but for simplicity I used BorderColor. Of course you have to modify the code so that it meets your validation requirements.

Regards,
Venelin
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Input
Asked by
Arun Kumar
Top achievements
Rank 2
Answers by
Venelin
Telerik team
Arun Kumar
Top achievements
Rank 2
Share this question
or