RadColorPicker Validation

6 posts, 0 answers
  1. Pradeep Enugala
    Pradeep Enugala avatar
    55 posts
    Member since:
    Apr 2010

    Posted 22 May 2010 Link to this post

    Hi,
           How to add RequiredFildValidator or Custom Validator for RadColorPcker?
           Iam getting "Control 'RadColorPicker' referenced by the ControlToValidate property of 'RequiredFieldValidator'  
          cannot be validated
    " error message When RequiredFieldValiator is aded to RadColorPicker.
    Thank you,
    Durga.
  2. Tsvetie
    Admin
    Tsvetie avatar
    1517 posts

    Posted 26 May 2010 Link to this post

    Hi Durga,
    You should use a CustomValidator control without setting its ControlToValidate property. You can use either the ClientValidationFunction to validate the color picker client-side, or the ServerValidate event of the validator to validate the color picker server-side.

    All the best,
    Tsvetie
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. subhashini T
    subhashini T avatar
    10 posts
    Member since:
    Apr 2010

    Posted 10 Jun 2010 Link to this post

    Not setting the controltovalidate for radcolorpicker does work but whenever validation fails, the related error message doesn't get displayed, unlike the usual case(for the other controls).  Any specific reasons for the same?
  5. Tsvetie
    Admin
    Tsvetie avatar
    1517 posts

    Posted 15 Jun 2010 Link to this post

    Hi subhashini T,
    In case you do not set the ControlToValidate property of the custom validator, you must check yourself whether the value of the control is valid. For example, in case you are using client-side validation, you use the IsValid property of the arguments object:
    <script language="javascript">
       function ClientValidate(source, arguments)
       {
            if (arguments.Value % 2 == 0 ){
                arguments.IsValid = true;
            } else {
                arguments.IsValid = false;
            }
       }
    </script>

    For server-side validation, you use the IsValid property of the args object:
    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;
             }
          }

    Additional information is available in MSDN:
    1. CustomValidator control
    2. ClientValidationFunction
    3. ServerValidate

    Regards,
    Tsvetie
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  6. Joshy Varghese
    Joshy Varghese avatar
    9 posts
    Member since:
    Mar 2009

    Posted 19 Jul 2010 Link to this post

     

    Can you explain how OnServerValidate will fire with out ControlTo Validate. In my debug OnServerValidate event is not firing at all.

    <telerik:RadColorPicker ID="cPicker1" runat= "server" ShowIcon="true" ></telerik:RadColorPicker>
    <asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="Select differnt color"
    OnServerValidate="ColorPickerValidate" ></asp:CustomValidator>


    protected void ColorPickerValidate(object source, ServerValidateEventArgs args)
    {
    if (ColorTranslator.ToHtml(cPickerBodyBg.SelectedColor=="#FFFFF))
    {
    args.IsValid = false;
    }
    }

    Thanks!

  7. Tsvetie
    Admin
    Tsvetie avatar
    1517 posts

    Posted 22 Jul 2010 Link to this post

    Hi Joshy Varghese,
    The handler that you have attached will be called on postback. For example, in case you add an ASP Button control and you click that button, the ServerValidate event of the custom validator will be raised even though the ControlToValidate property is not set. Have a look at the paragraph below - it is taken from MSDN:

    quote:
    It is possible to use a CustomValidator control without setting the ControlToValidate property. This is commonly done when you are validating multiple input controls or validating input controls that cannot be used with validation controls, such as the CheckBox control. In this case, the Value property of the arguments parameter passed to the event handler for the ServerValidate event and to the client-side validation function always contains an empty string (""). However, these validation functions are still called, where appropriate, to determine validity on both the server and client. To access the value to validate, you must programmatically reference the input control you want to validate and then retrieve the value from the appropriate property. For example, to validate a CheckBox control on the server, do not set the ControlToValidate property of the validation control and use the following code for the handler for the ServerValidate event.

    In case you have configured your color picker control to postback the page, you should additionally call the Validate method of the Page manually in the handler for the ColorChange event of the color picker control:
    <telerik:RadColorPicker ID="cPicker1" runat="server" ShowIcon="true"
        AutoPostBack="true" OnColorChanged="OnColorChanged">
    </telerik:RadColorPicker>

    protected void OnColorChanged(object source, EventArgs args)
    {
        Page.Validate();
    }

    Regards,
    Tsvetie
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017