Validate Data Before Submitting

2 posts, 0 answers
  1. Trevor
    Trevor avatar
    13 posts
    Member since:
    Jun 2011

    Posted 18 Oct 2011 Link to this post

    I have a several maskedinputboxes which I have databound to a domain data source and it exposes the validation error from the RIA metadata properly:

    The problem I am having is checking for a validation error before passing a Datasource.Submit(). Even though there is a red box up on the screen. I can't figure out a way to check the form(Grid) or even the control for this in the codebehind when the user presses a Submit button. 

     <telerik:RadMaskedTextBox Name="CState" MaskType="Standard" Mask="LL" EmptyContent="State" Value="{Binding State,Mode=TwoWay,NotifyOnValidationError=True}"  />

    I've tried this method on just about every relevant object and it always returns false.

    These Controls are on a grid which is bound to the domain data source.
    <Grid x:Name="LayoutRoot" Background="Transparent" DataContext="{Binding Data, ElementName=CustomerData}" >
  2. Nedyalko Nikolov
    Nedyalko Nikolov avatar
    871 posts

    Posted 21 Oct 2011 Link to this post

    Hi Trevor,

    Generally Validation.GetHasErrors(DO) or Validation.GetErrors(DO) will return a correct value when there is a binding error directly on DO passed as argument. For example as in your picture Validation.GetHasErrors(_ValidationForm) will return false, while Validation.GetHasErrors(stateTextBox) should return true. So you can use code similar to the following one:

    bool hasBindingError  = false;
    foreach(var control in ValidationForm.ChildrenOfType<Control>())
        if (Validation.GetHasErrors(control))
            hasBindingError = true;

    Another possible approach is to use RIA services entities support for INotifyDataErrorInfo interface and check INotifyDataErrorInfo.GetErrors(propertyName) or hook for INotifyDataErrorInfo.ErrorsChanged event.

    Kind regards,
    Nedyalko Nikolov
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Back to Top