Validation Rule Question

Validation Rule Question

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


Steven posted on Monday, May 29, 2006

 

Is it possible to create a validation rule that will check a users input against values in a database table.  For example if my database contained a table that stores the list of all valid US zip codes.  I would like to create a validation rule that will check the users input in the zip Code entry field against the valid zip codes in the table.

 

And if so is it possible to only have this type of validation occurs when the user chooses to save the form instead of doing it when the user tabs off the field which could cause a delay as it goes back to the server to do the check.

 

Thanks

RockfordLhotka replied on Monday, May 29, 2006

Yes. To do this, you can either use a ReadOnlyBase or CommandBase object - which is often private and nested within your business object to avoid cluttering the object model (either that, or put it in a sub-namespace).

You can see how a command object like this might work by looking at how the Equals() methods are implemented in Project and Resource, as discussed in Chapter 7. In your case however, you probably won't have a public static/Shared method like Equals(), but rather will have a private method that invokes the command.

You can invoke the command from within a rule method - but in that case it would run any time CheckRules() is called for the associated property, which doesn't sound like what you want.

So instead, you can override Save() and call it there.

Steven replied on Tuesday, May 30, 2006

Rocky did you mean to look at how the Equals() or Exists() method are implemented in Project and Resource ?

 

 

RockfordLhotka replied on Tuesday, May 30, 2006

Exists...


From: Steven [mailto:cslanet@lhotka.net]
Sent: Tuesday, May 30, 2006 9:32 PM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] Validation Rule Question

Rocky did you mean to look at how the Equals() or Exists() method are implemented in Project and Resource ?

phowatt replied on Tuesday, May 30, 2006

I typically create a list class using the ReadOnlyBase from Rocky's framework and this way the entire list is resident in memory.  Since it is in memory the lookup is very fast and does not require any more trips to the server and doing the check upon tabbing from the field is not a problem. I have written a class I call the GlobalListManager that uses shared methods to populate any and all lists that I might need in a class and where most lists do not need to be refreshed some do so I can refresh a list whenever it's need using my GlobalListManager methods.

Copyright (c) Marimer LLC