Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Data validation in silverlight


Published on

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Data validation in silverlight

  1. 1. Validation Errors<br />Mahender<br />Senior Software Engineer<br />United Health Group<br />
  2. 2. Mahender Sarangam<br />Having 5 years of experience on .NET Technologies. Working as a Senior Software Engineer in United Health Group (UHG India Information Service Ltd.). Worked with Big Firms like Deloitte Consulting & Wipro Technology. <br />Got Technical Acquaintance on Technologies like C#, ASP.NET,AJAX, LINQ, Silverlight, WPF,WCF ,SQL Server, Team Foundation Server(TFS) and SharePoint Technology. <br />MCTS Certified in Web Technologies.<br />Blog : <br />
  3. 3. What are Validation Errors?<br /><ul><li> Silverlight provides several ways to validate data. The </li></ul> simplest and oldest approach is to use exception-based <br /> validation.<br /><ul><li> In Silverlight 3 , Validation is performed using </li></ul> “ValidationOnException” property in Binding expression <br /> to throw validate errors .<br /><ul><li>Incorrect data type: For example, a numeric property like UnitCost can’t accommodate letters or special characters. Similarly, it can’t hold extremely large numbers (numbers larger than 1.79769313486231570E+308).
  4. 4. Property setter exception: For example, a property like UnitCost may use a range check and throw an exception if you attempt to set a negative number.
  5. 5. Read-only property: This can’t be set at all.</li></li></ul><li>
  6. 6. To enable the BindingValidationFailed event, you must set ValidatesOnExceptionsto true (to detect errors) and NotifyOnValidationError to true (to fire the validation events). Whenever NotifyOnValidationError is true, BindingValidationError is fired and its bubble event,which can be handled in parent elements.<br />For example :<br /><TextBoxMargin="5" Grid.Row="2" Grid.Column="1" x:Name="txtUnitCost” Text="{Binding UnitCost, Mode=TwoWay, ValidatesOnExceptions=True,<br />NotifyOnValidationError=True}"></TextBox><br />
  7. 7. Steps for Data Object Validation<br />There are three basic steps to follow<br />Implement the IDataErrorInfo or INotifyDataErrorInfo interface in your data object.<br />Tell the data binding infrastructure to check the data object for errors and show error notifications. If you’re using the IDataErrorInfo interface, you set ValidatesOnDataErrors to true. If you’re using the INotifyDataErrorInfo interface, you set ValidatesOnNotifyDataErrorsto true<br />Optionally, set NotifyOnValidationError to true if you want to receive the BindingValidationFailedevent.<br />Optionally, set the ValidatesOnExceptions property to true if you want to catch other types of errors, such as data conversion problems.<br />private <string, <string>> errors = new <string, List<string>>();<br />public event EventHandler<DataErrorsChangedEventArgs> ErrorsChanged;<br />
  8. 8. Thank you<br />