.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Articles >> Silverlight >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Validating Textbox on Lost Focus in RIA Service,Silverlight4

Posted By:Manas Patnaik       Posted Date: January 27, 2011    Points: 75    Category: Silverlight    URL: http://www.dotnetspark.com  

Workaround with validation issue of TextBox in RIA service.
 

While working on my post on "Data Binding in Silverlight with RIA and Entity Framework - Part 3 (Validating Input Data)" , a series of article on RIA Services   , i came across a situation where i wanted to validate my textbox control on a particular event.For e.g on LostFocous.As we know the the validation fire only when the source property value gets changed and the entity gets updated. But you might have known that the Textbox TextProperty gets updated on LostFocus (MSDN Link) .This is the default behaviour but it does not work with RIA Service in Textbox.Baring teeth smile

And most of the time the validation on the client side need to be triggered explicitly on our demand.For e.g refer my StatesOfIndia Application as the user provides some value at state Name and moves on ,  the validation need to be fired.

So to implement the validation on LostFocus of StateName textbox follow the steps bellow ,

Make Sure you have Implemented the validation Rule at Model Entity Member

In the Metadata file i have added Required Attribute for the statename.

image

Change the UpdateSourceTrigger of Textbox

Then change the UpdateSourceTrigger property of the binding of the Textbox to explicit mode.

image

Update the Source at your desired event

As i  want to force updation of data as well as fire validation on lost focus event , so i am going to get the binding expression  of the control and update its source.

  1. private void txtStateName_LostFocus(object sender, RoutedEventArgs e)
  2. {
  3. System.Windows.Data.BindingExpression bexpress = txtStateName.GetBindingExpression(TextBox.TextProperty);
  4. bexpress.UpdateSource();
  5. }

As soon as the property gets changed the validation will fire .

This is for now , soon i will post with a detailed article on validation.Stay Tuned Smile


 Subscribe to Articles

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend