QuoteReplyTopic: Client side validation Posted: 12-Mar-2012 at 3:21am
Hello, I've got an object I share between client/server defined as
[DataContract] public class TestClass { [DataMember] public int ID {get;set;} [DataMember] public string Description {get;set;} [DataMember] public decimal Value{get,set;} }
I've it defined in a viewmodel I use to insert this kind of data
public class MyViewModel : Screen { public TestClass myTestClass { get { return _myTestClass } set { _myTestClass = value; ... } } }
how can I validate this object ? I've done other validation using the method proposed at http://www.lyquidity.com/devblog/?p=71 but I've not the single properties in my viewmodel, just the poco object
I forget if you are doing WPF or Silverlight, but you'll have to implement IDataErrorInfo (WPF) or INotifyDataErrorInfo (Silverlight) in the POCO. You also have the option of simply throwing exceptions in your setters and set ValidatesOnExceptions to true in the binding. Neither DevForce nor Cocktail currently provides anything that helps you with implementing validation in your own POCOs. This is something we are considering, but at the moment you'll have to implement it yourself.
in my testing I did so, but I've got a problem... I need to disable the ok button based on if there're validation error.... using IDataError info, how do I check if there're error?
You are better off adding a boolean property to your object that indicates whether it has validation errors or not. IDataErrorInfo doesn't lend itself for this task.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum