Validation Red border style

6 posts, 0 answers
  1. Arun Kumar
    Arun Kumar avatar
    60 posts
    Member since:
    Nov 2009

    Posted 28 Nov 2013 Link to this post

    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.
  2. Venelin
    Admin
    Venelin avatar
    352 posts

    Posted 03 Dec 2013 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Arun Kumar
    Arun Kumar avatar
    60 posts
    Member since:
    Nov 2009

    Posted 04 Dec 2013 Link to this post

    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 ?

  5. Venelin
    Admin
    Venelin avatar
    352 posts

    Posted 09 Dec 2013 Link to this post

    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.
  6. Arun Kumar
    Arun Kumar avatar
    60 posts
    Member since:
    Nov 2009

    Posted 11 Dec 2013 Link to this post

    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 ?
  7. Venelin
    Admin
    Venelin avatar
    352 posts

    Posted 14 Dec 2013 Link to this post

    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017