Skip to main content
Home Forums Silverlight Programming Silverlight Controls and Silverlight Toolkit User control input validation consideration
4 replies. Latest Post by Mog Liang - MSFT on August 17, 2009.
(0)
Jessmmy
Member
54 points
64 Posts
08-11-2009 2:02 AM |
Guys,
I have a question about how to implement user input validation here.
System.ComponentModel.DataAnnotations attributes can be added to business objects to carry out the validation in conjunction with control bindings. To do this, we get make use of all these data input validation controls.
In my case, I just want to add some validation to some search criteria, like required field, data format and etc. Which approach should I go for? Should I just implement my owner logic by writing up some functions?
Thanks
Sledge70
Contributor
5892 points
1,042 Posts
08-11-2009 5:34 AM |
Hard question to answer really as it probably comes down to personal preference.
I'd build an entity that implements INotifyPropertyChanged with all my validation in it and bind that up to xaml and use the built in visualstates on the toolkit controls.
You can take control of when validation occurs by using the method I posted in this thread:http://silverlight.net/forums/t/111830.aspx
jessmmy
08-11-2009 11:23 PM |
I'm using linq to sql to auto generate all these entity classes and data access code. If I want to add data annotation attribute to those auto generated classes, i have to use metadatatype class becuase partial property is not supported. All these classes are called by silverlight client throught WCF.
Normally, the code will look like this if we use non partial class.
[Required(ErrorMessage="User Name is required")] public string UserName { get { return _UserName; } set { Validator.ValidateProperty(value, new ValidationContext(this, null, null) { MemberName="UserName"}); _UserName = value; } }
If we use partial class here
[MetadataType(typeof(UserMetaData))] public partial class User { } public class UserMetaData { [Required(ErrorMessage = "User Name is required.")] public string UserName; } My question will be how can i call Validator.ValidateProperty(value, new ValidationContext(this, null, null) { MemberName="UserName"}); here?>I'm just confused about these metadatatype and partial class usage here.
[MetadataType(typeof(UserMetaData))] public partial class User { } public class UserMetaData { [Required(ErrorMessage = "User Name is required.")] public string UserName; }
My question will be how can i call Validator.ValidateProperty(value, new ValidationContext(this, null, null) { MemberName="UserName"}); here?>
I'm just confused about these metadatatype and partial class usage here.
08-12-2009 2:53 AM |
I just had another question.
Is System.ComponentModel.DataAnnotations.Validator only used in silverlight project because I can't find this class from normal c# project?
Thanks guys
Mog Lian...
All-Star
15908 points
1,549 Posts
08-17-2009 3:47 AM |
Hi,
jessmmy:My question will be how can i call Validator.ValidateProperty(value, new ValidationContext(this, null, null) { MemberName="UserName"}); here?>I'm just confused about these metadatatype and partial class usage here.
The question I understand, is how to modify WCF generated entities. please check this post
http://silverlight.net/forums/p/114537/262069.aspx#262069
Jessmmy:Is System.ComponentModel.DataAnnotations.Validator only used in silverlight project because I can't find this class from normal c# project
If you installed RIA service, then you could find Server-side library containing Validator at
Thanks,