ASP.NET FormView with LLBLGenProDataSource

Posts   
 
    
Val
User
Posts: 37
Joined: 14-Nov-2008
# Posted on: 25-Nov-2008 23:53:25   

I have a FormView that is using a LLBLGenProDataSource and a custom entity validator using LLBL DI framework. I am trying to catch the validation exception and at the same time preserve the data entered in form view. In PerformWork event I get the exception but all the form elements values are lost.

How can I check in formview before insert/update events (they fire before LLBLGenProDataSource PerformWork) if the changed entity is valid? I tried to get a reference to the entity to insert in FormView ItemInserting but LLBLGenProDataSource.UnitOfWorkObject.GetEntityElementsToInsert() returns null.

Also, what are the best practices in propagating the validation errors back to UI. Is it possible to use an asp.net custom validator wrapped around the custom entity validator?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 26-Nov-2008 05:46:34   

I think here is recommended to validate GUI-side too. This way the PerformWork wont be called unless all field values are ok.

How your validator code looks like? Please post (or attach) the validator code.

David Elizondo | LLBLGen Support Team
Val
User
Posts: 37
Joined: 14-Nov-2008
# Posted on: 26-Nov-2008 16:16:51   

daelmo wrote:

I think here is recommended to validate GUI-side too. This way the PerformWork wont be called unless all field values are ok.

How your validator code looks like? Please post (or attach) the validator code.

I am using the classic ASP.NET validators for simple validation like for required field, data type, length. For more complex business rules I have created a custom validator for the my llbl entity. I would like to call ValidateEntity() before the PerformWork triggers like in formView ItemInserting event.

So far my validator looks like this:

[DependencyInjectionInfo(typeof(MyEntity), "Validator", ContextType = DependencyInjectionContextType.Singleton)]
public class MyEntityValidator: ValidatorBase
{
    public override void ValidateEntityBeforeSave(IEntityCore involvedEntity)
    {
        MyEntity toValidate = involvedEntity as MyEntityEntity;

        throw new ORMEntityValidationException("Custom Validation Exception Test", toValidate);
    }

    public override void ValidateEntity(IEntityCore involvedEntity)
    {
        ValidateEntityBeforeSave(involvedEntity);
    }

}
Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 26-Nov-2008 17:00:22   

I would like to call ValidateEntity() before the PerformWork triggers like in formView ItemInserting event.

Please use the LLBLGenProDataSource events: EntityInserting, EntityUpdating & EntityDeleting. And you can catch the involved entity using the CancelableDataSourceActionEventArgs.

Val
User
Posts: 37
Joined: 14-Nov-2008
# Posted on: 26-Nov-2008 17:40:15   

Walaa wrote:

I would like to call ValidateEntity() before the PerformWork triggers like in formView ItemInserting event.

Please use the LLBLGenProDataSource events: EntityInserting, EntityUpdating & EntityDeleting. And you can catch the involved entity using the CancelableDataSourceActionEventArgs.

Thank you,

That is what I was looking for.