This is a migrated thread and some comments may be shown as answers.

Validate Data Before Submitting

1 Answer 73 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Trevor
Top achievements
Rank 1
Trevor asked on 18 Oct 2011, 06:28 PM
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.
Validation.GetHasError(_ValidationForm)

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}" >

1 Answer, 1 is accepted

Sort by
0
Nedyalko Nikolov
Telerik team
answered on 21 Oct 2011, 08:05 AM
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;
        break;
    }
}

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 >>

Tags
General Discussions
Asked by
Trevor
Top achievements
Rank 1
Answers by
Nedyalko Nikolov
Telerik team
Share this question
or