ValidateFieldValue(), what good is it?

Posts   
 
    
clint
User
Posts: 145
Joined: 15-Nov-2005
# Posted on: 02-Mar-2007 23:48:44   

I had a question about overriding ValidatorBase::ValidateFieldValue().

The documentation says if you return false, it doesn't set the value for the field. That seems fine. But how does the calling code that set the value find out that the value is invalid? If you can't find out that the value was invalid, what good is this function?

The documentation mentioned filling in the IDataErrorInfo Error, but IDataErrorInfo seems to be geared towards providing error information to Windows UI. It doesn't seem very helpful for web applications.

PilotBob
User
Posts: 105
Joined: 29-Jul-2005
# Posted on: 03-Mar-2007 00:12:15   

clint wrote:

I had a question about overriding ValidatorBase::ValidateFieldValue().

The documentation says if you return false, it doesn't set the value for the field. That seems fine. But how does the calling code that set the value find out that the value is invalid? If you can't find out that the value was invalid, what good is this function?

The documentation mentioned filling in the IDataErrorInfo Error, but IDataErrorInfo seems to be geared towards providing error information to Windows UI. It doesn't seem very helpful for web applications.

You can use SetFieldError (I think it is)... You can access the field errors from the Entity. I think I talked Frans into making that collection public. You can cast to IDataErrorInfo and use the info in a web app if you want.

BOb

clint
User
Posts: 145
Joined: 15-Nov-2005
# Posted on: 03-Mar-2007 00:20:22   

It seems like IDataErrorInfo is used in combination with an ErrorProvider to provide errors for bound fields on a windows form. As far as I know, ASP.net doesn't use IDataErrorInfo. I suppose a web application could get the errors out, but it needs to know what name the errors were indexed with, and how would it know that?

Outside of using it with IDataErrorInfo, does anyone use any other methods to alert the calling code that an error occurred?

jmeckley
User
Posts: 403
Joined: 05-Jul-2006
# Posted on: 04-Mar-2007 16:22:14   

I use asp.net validators for simple field checks. I use the LLBL validators for complex entity(s) validation. Here I throw an exception in the validator. then catch the exception and display the message to the user.

the new Ent Lib .Net 3.0 validation seems simple enough in theory, but doesn't tie to LLBL easily since it's based on attributes. I know Frans and other developers have an on going discussion about this.

I haven't tried using the IDataErrorInfo object in asp.net as all the examples I have seen relate back to Windows apps.

PilotBob
User
Posts: 105
Joined: 29-Jul-2005
# Posted on: 05-Mar-2007 16:10:34   

clint wrote:

It seems like IDataErrorInfo is used in combination with an ErrorProvider to provide errors for bound fields on a windows form. As far as I know, ASP.net doesn't use IDataErrorInfo.

True, but there is no reason that you can't write your own code that accesses this interface. That is the whole point of using an interface, so it can be implemented in many ways but provide a common API for consumers of it. So, you could actually create a base page class with some generic code that access the entities IDataErrorInfo interface to determine if there are any errors in the entity.

If I get a chance I will try to create some example code of this... that is if anyone is interested in it.

BOb

jmeckley
User
Posts: 403
Joined: 05-Jul-2006
# Posted on: 05-Mar-2007 16:17:56   

i would be interested in a sample use of IDataErrorInfo for webapps.

oki
User
Posts: 27
Joined: 12-Sep-2007
# Posted on: 22-Nov-2007 17:38:16   

jmeckley wrote:

i would be interested in a sample use of IDataErrorInfo for webapps.

found a sample in this blog:

http://dotnetslackers.com/ASP_NET/re-63537_IDataErrorInfo_for_ASP_NET.aspx