ValidateFieldValue() not called for bound control if data not changed

Posts   
 
    
clint
User
Posts: 150
Joined: 15-Nov-2005
# Posted on: 13-Jul-2010 16:43:33   

LLBLGen Version: 2.6 Final (April 15th, 2009) Template: adapter .NET Version: 2.0

I have controls on a Windows form bound to fields of an Entity. As a user tabs off a control on the form, ValidateFieldValue() is automatically called and if the data the user entered is invalid, ValidateFieldValue() will call the entity's SetEntityFieldError() which will trigger the ErrorProvider component on the form to display the error.

But I noticed that if you don't change the data for a form control, the program will not try to set the entity field, therefore ValidateFieldValue() won't be called. So how can I display an error if, for example, a user tabs off a textbox for a required field without entering a value?

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 13-Jul-2010 21:11:41   

You will either need to validate the control on the form yourself, or validate the entire entity before it is saved - see http://www.llblgen.com/documentation/2.6/Using%20the%20generated%20code/gencode_validation.htm#entityvalidation for more information.

Matt

clint
User
Posts: 150
Joined: 15-Nov-2005
# Posted on: 13-Jul-2010 23:52:44   

MTrinder wrote:

You will either need to validate the control on the form yourself, or validate the entire entity before it is saved - see http://www.llblgen.com/documentation/2.6/Using%20the%20generated%20code/gencode_validation.htm#entityvalidation for more information.

Matt

Thanks for the reply.

Actually I already validate the entire entity before saving too, but thanks for the suggestion anyways.

I was hoping there was some commonly used strategy that would force ValidateFieldValue() to be called so I don't have to write extra validation code in the form itself.

I really only need to worry about this situation when adding a new record. When editing a record, to make a field blank, the user would have to delete the existing data in the textbox which would trigger ValidateFieldValue().

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 14-Jul-2010 05:39:48   

The thing is: Validators can't validate data if actually there is no data to validate. When updating an entity, if the data is there, somehow it's valid, if value doesn't change then in theory everything is ok. When inserting an entity, if no data in entered in the field, there is nothing to validate. In that case you should validate the entity to find required fields that are blank/null. So that is the common strategy simple_smile

David Elizondo | LLBLGen Support Team