How to remove one or more fields from the DataForm.Validating() event in Silverlight 4? -


i have data form bound object properties decorated system.objectmodel.dataannotation attributes validaton.

the problem facing properties of class conditionally needed , not need validated. example when admin of app decides edit user, or may enter password/password confirm/password question/password answer. or he/she may entirely skip properties.

so if admin decides enter of 4 fields, have present , validation rules these fields have applied. if admin wants change firstname, lastname, email, or whatever other arbitrary properties - password related fields not need validated.

is there way "exclude" them validation process?

this sample of object work with:

public class registrationdata {    public string firstname { get; set; }    public string lastname { get; set; }    public string email { get; set; }    public string username { get; set; }    public string password { get; set; }    public string passwordconfirm { get; set; }    public string passwordquestion { get; set; }    public string passwordanswer { get; set; } } 

i have dataform called registrationform in xaml , error in code:

private void registrationbutton_click(object sender, routedeventargs e) {    if( this.registerform.validateitem() )    {        //does not pass validaton if password properties not filled in.    } } 

any ideas on how fix it?

i thinking of using 2 dataforms... , split user object in two, involves lot of code...

i recommend use inotifydataerror interface on registrationdata object.

    public string labelwrapper     {                 {             return this.label;         }         set         {             validaterequired("labelwrapper", value, "label required");             validateregularexpression("labelwrapper", value, @"^[\w-_ ]+$", "characters allowed (a-z,a-z,0-9,-,_, )");             this.label = value;             this.raisepropertychanged("labelwrapper");         }     }      public string dependentlabelwrapper     {                 {             return this.dependentlabel;         }         set         {             if(labelwrapper != null){                 validaterequired("dependentlabelwrapper", value, "label required");                 validateregularexpression("labelwrapper", value, @"^[\w-_ ]+$", "characters allowed (a-z,a-z,0-9,-,_, )");              }             this.dependentlabel = value;             this.raisepropertychanged("dependentlabelwrapper");         }     } 

i recommend @ link http://blogs.msdn.com/b/nagasatish/archive/2009/03/22/datagrid-validation.aspx learn more different validation types.

also msdn has nice explanation on how use it

http://msdn.microsoft.com/en-us/library/system.componentmodel.inotifydataerrorinfo%28vs.95%29.aspx


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -