Validation rule not firing consistently?

Validation rule not firing consistently?

Old forum URL: forums.lhotka.net/forums/t/4669.aspx


stacy.odell posted on Friday, April 11, 2008

I am using 2.1.4 and I have a custom validation rule set up on a property (I am not using any rule priorities -- they are all 0).  I also call PropertyHasChanged() in my property setter.

In my UI I am setting the property manually -- not databinding.

The problem is this -- the validation rule will get called the first time this property is set, and the validation will work just fine.  But if the validation fails, and the end user changes the value a subsequent time (presumably to fix the error), I can see via breakpoints that the PropertyHasChanged method is getting called -- but the custom validation rule code never runs again.

Any ideas?

One thing to note -- I do call the PropertyHasChanged overload with no parameter name -- PropertyHasChanged();  -- would that have something to do with it?

sergeyb replied on Friday, April 11, 2008

Even though it is not good to use parameter-less version of PropertyHasChanged(), it should work on debug mode.  I would change it anyway, because those calls were deprecated in subsequent version of CSLA.  However, I think this should work regardless.  I would put breakpoint inside the rule itself to verify.

 

Sergey Barskiy

Senior Consultant

office: 678.405.0687 | mobile: 404.388.1899

cid:_2_0648EA840648E85C001BBCB886257279
Microsoft Worldwide Partner of the Year | Custom Development Solutions, Technical Innovation

 

From: stacy.odell [mailto:cslanet@lhotka.net]
Sent: Friday, April 11, 2008 10:14 AM
To: Sergey Barskiy
Subject: [CSLA .NET] Validation rule not firing consistently?

 

I am using 2.1.4 and I have a custom validation rule set up on a property (I am not using any rule priorities -- they are all 0).  I also call PropertyHasChanged() in my property setter.

In my UI I am setting the property manually -- not databinding.

The problem is this -- the validation rule will get called the first time this property is set, and the validation will work just fine.  But if the validation fails, and the end user changes the value a subsequent time (presumably to fix the error), I can see via breakpoints that the PropertyHasChanged method is getting called -- but the custom validation rule code never runs again.

Any ideas?

One thing to note -- I do call the PropertyHasChanged overload with no parameter name -- PropertyHasChanged();  -- would that have something to do with it?



stacy.odell replied on Friday, April 11, 2008

Thanks Sergey -- I had no idea calling that without the property name was not advisable.  I guess I need to go back and edit those code snippets I downloaded and have been using.  :)

I'll give that a try when I get back to the office.

-- Stacy

JoeFallon1 replied on Friday, April 11, 2008

Calling wihtout the property name was supposed to benefit you by eliminating the need to have string literals in your code - if you have a typo or an incorrect case then things don't work right. The problem is it relies on a stack trace to find the property name and it was later learned that it was not a reliable way to handle it in all situations. There were some edge cases where it failed. That is why Rocky deprecated it in 3.5.

I use Codesmith so I never had a problem with using the String literals since they were code generated anyway.

I agree with Sergey that the rule should run so definitely add a break point to it. Be sure the property name spelling is the same everywhere! Including case sensitivity. You may be calling it or adding it one way but then subsequent calls have incorrect spelling and it won't run.

Joe

Copyright (c) Marimer LLC