Validation always return true

Posted by: a.sharov on 27 January 2022, 10:46 am EST

  • Posted 27 January 2022, 10:46 am EST

    Hi.

    I have uc with some ctrls+validation logic which validates that textboxes are mot empty and have valid path (one of them). But when I launch app and call user control validation (userControl11.ValidateChildren(ValidationConstraints.Visible)) it always returns true, even if UI indcates error. Plus for some reason I don’t see error hints when navigate above red icon near control.

    Source – https://drive.google.com/file/d/1L6eDhGrdzgL9Y0CBwa8mc1mfo_HjZO7G/view?usp=sharing

    Thanks in advance.

  • Posted 27 January 2022, 10:47 am EST

    Sry, forgot to ask question – what I’m doing wrong? Why it is always true even I setup e.Cancel = true;

  • Posted 28 January 2022, 2:42 am EST

    Hi,

    The ValidateChildren always return true since you have set the CanLoseFocus to true. The validating event does not allow the Textbox to lose focus if the validation fails i.e. e.Cancel is set to true. To overcome this, you can use the CanLoseFocus property of ErrorInfo of our C1TextBox, which allows the focus to be lost when set to true.

    If you want the ValidateChildren to return false, you have to set the CanLoseFocus property to false which will make the control validation work as a normal TextBox.

    To make the best use of ErrorInfo and other functionalities that C1Textbox offer, we suggest you use the PreValidation and PostValidation of C1Textbox to perform validation.

    The ToolTip property of your ‘epError’ C1SuperErrorProvider was set to none, that’s why it was not showing the error tooltip message. You need to set it to a C1SuperToolTip to show the error tooltip messages.

    Regards.

    Avnish

  • Posted 28 January 2022, 9:58 am EST

    Hi.

    Thank you for reply. I use CanLoseFocus = true because I don’t want to be blocked on errored control. I want to be able to switch between controls, press buttons or close app. In case I’ve focused on errored control the only way I can switch is to enter valid data, but what if I changed my mind + validation is cost operation (cloud or db access)? Again, in my prev question about path selection, I won’t be able to press browse button, only enter path by hand. Very inconvenient.

    So, is there any way to use best of both worlds – lost focus and being able to validate properly, return false? Maybe introduce some fake control (hidden) control, the one which will have CanLoseFocus =false but in the same time uneditable (like label?)?

    use the PreValidation and PostValidation of C1Textbox to perform validation.

    I found this approach very confusing. I just need simple validation mechanism where each control (not textbox specifically, any) could validate itself and provide result of validation.

  • Posted 31 January 2022, 7:39 am EST

    Hi,

    We have escalated the issue to the development team to get their insights on the issue and will let you know as soon as we have an update.

    [Internal Tracking ID : C1WIN-26663]

    Regards

    Avnish

  • Posted 1 February 2022, 6:22 am EST

    Hi,

    As per the development team, it is the designed behavior since C1TextBox can’t lose focus if canceled from the Validating event. The team has provided a workaround for your use case, we hope it’ll be helpful in achieving your requirements. Please refer to the attached sample.

    Regards

    Avnish

    Valid_always_true_workaround.zip

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels