Validation
Retired Content |
---|
This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist. |
The latest Enterprise Library information can be found at the Enterprise Library site. |
On this page: |
---|
Validation in a Silverlight Application |
Validation is a very important aspect of any line of business (LOB) application. A good validation implementation helps prevent data corruption and enforces compliance with business rules.
Microsoft® Silverlight® allows you to build applications that provide a rich user experience, and part of a rich experience is good validation. When a validation error occurs, the user should get clear and obvious feedback as quickly as possible so he is not left wondering what is happening. Simple validation checks might be performed as the user is typing, or more complex validation rules might be run in the background while the user is still performing some task. Validation error messages should provide a clear description of the cause of the error, with an indication of how the user can solve the problem.
In this chapter, we'll examine the most common validation scenarios for Silverlight LOB applications and how the Validation Application Block from the Enterprise Library 5.0 Silverlight Integration Pack can help you implement those scenarios in your application. We'll also discuss how the Validation Application Block can be applied to a Windows® Communication Foundation (WCF) Data Services application and how you can use the Validation Application Block to extend the validation support provided by WCF RIA Services.
Validation in a Silverlight Application
A Silverlight LOB application typically consists of a Silverlight client that communicates with web services to read or modify data in data sources such as databases. As the data flows through the user interface all the way to the data source, there are several places to handle validation. Validation errors that occur in this process will typically flow back to the user interface (UI):
- The user enters data in a control, for example a TextBox, that is bound to a property on your model. In this context, a model can refer to a View Model from the Model View ViewModel (MVVM) pattern, but also to an entity class generated by WCF RIA Services or a custom business entity. When the user leaves the TextBox, the Silverlight data binding engine will attempt to convert the value in the TextBox to the type of the property and update the model. If the value in the TextBox cannot be converted to the type of bound property, then the data binding engine will throw an exception. You can then use an error style to display an error message.
Sharon Says: This is such a great feature from Silverlight data binding. In other technologies, such as ASP.NET web forms or Windows Forms, this is much harder. In those technologies you have to manually perform data binding and type conversion, which is tedious work and often error prone. Next Topic | Previous Topic | Home
Last built: July 8, 2011