How can I find out the validation status of a Silverlight usercontrol? -
i have silverlight usercontrol few fields on bound via ria services database. using notifyonvalidationerror=true, validatesonexceptions=true on these fields , validationsummary control show errors fields. works fine.
however, on usercontrol have "save" button call context.submitchanges() when clicked. problem button can clicked (and submitchanges called )even when there still errors present.
how determine whether there validation errors still present, or there anyway of binding isenabled property of save button validation status?
to stop save button being available when there client side validation errors still in effect try this.
in class (code behind or view model) have provides current instance of ria entity working with.
public sampleriaentity selectedentity { get; set; }
using extension method:
public static class riaextensions { public static bool checkvalidation<t>( t riaentity ) t : entity { validationcontext vc = new validationcontext( riaentity, null, null); icollection<validationresult> validationresults = new list<validationresult>(); return ( validator.tryvalidateobject( riaentity, vc, validationresults ) == true ); } }
you provide property use isenabled on save button.
public bool haserrors { { return selectedentity.checkvalidation<sampleriaentity>(); } }
this run through validation rules available on client side. save still not commit if there server side rules weren't satisfied.
Comments
Post a Comment