Sunday 14 February 2010

Asp.Net Dynamic Data – Data Type Part 2

In my previous post I listed the different DataType’s that dynamic data supports through its DataType attribute.

Like some of the previous attributes the DataType attribute supports multiple arguments, the difference between this attribute and the others with multiple arguments is you want to be looking to use the named parameters.

The available arguments are:

Argument Use
ErrorMessage Sets message to display if the control fails validation.
ErrorMessageResourceName Name of resource to use for displaying an error message. Often used to display a localized error message
ErrorMessageResourceType Used in conjunction with ErrorMessageResourceName to specify the type of resource

To use you simply specify the relevant named parameter and value to use:

[DataType(DateType.Date, ErrorMessage=”You must enter a valid date.”)]

And this should then display your error message when an invalid value is entered in the field but unfortunately this does not work.

It appears that there is a bug in the current implementation of Dynamic Data where it does not pick up the error message, or resource, that is specified  on the attribute.  It is possible to get Dynamic Data to use the attribute error message but that involves further code where you set the CompareValidator error message explicitly see this blog post by Rick Anderson for details.

No comments:

Post a Comment