I use Dynamic Data for a BackOffice application.
Here my problem, it is rather simple: how to translate (in French for example) the error message which is generated automstiquement by Framework during the validation of the data.
Example of message: “The DATUM_ACTIEF_BEGIN field is required.”
Thank you, that goes well for the messages with attribute of validation.
But there remains another problem.
For the problem of format of data, how then I can translate the following message which is posted for a field badly formatted “DateTime”: “Obligatory Field Unable to convert standard input G-string “dvdsvsdvvdsv” to “System.DateTime”.”
There is no attribute thus I cannot specify key resource!
You don't need a validation attribute - In my blog I use a non-existent attribute [DataType("dummy", -the [DataType("dummy", does not exist. Perhaps you could post your failing code. Are you having trouble
setting the format string for dateTime and getting a good error message when the input cannot be converted? If you like you can post your question in another language and I'll try to get someone to translate it for me.
<input name="ctl00$ContentPlaceHolder1$DetailsView1$__DATUM_ACTIEF_BEGIN$TextBox1" value="fdsfdsdfdsf" size="20" id="ctl00_ContentPlaceHolder1_DetailsView1___DATUM_ACTIEF_BEGIN_TextBox1" type="text">
Unable to convert input string 'fdsfdsdfdsf' to type 'System.DateTime'.
Date fin actif
<input name="ctl00$ContentPlaceHolder1$DetailsView1$__DATUM_ACTIEF_EIND$TextBox1" value="dfsdfsdfsdf" size="20" id="ctl00_ContentPlaceHolder1_DetailsView1___DATUM_ACTIEF_EIND_TextBox1" type="text"> Unable to convert input string 'dfsdfsdfsdf' to type
'System.DateTime'.
This is a known bug. I think it might be fixed in the preview version - I'll find out tomorrow. Using the new preview 4 versions you might not need to use the work around in my blog.
To work around this bug using the current release, you need to modify DynamicData\FieldTemplates\DateTime_Edit.ascx.cs and add something like
CompareValidator1.ErrorMessage = String.Format("Date début actif {0} ", Column.DATUM_ACTIEF_BEGIN);
jmvanbel
0 Points
4 Posts
Translate Error Messages
Mar 24, 2009 01:02 PM|LINK
Hello,
I use Dynamic Data for a BackOffice application.
Here my problem, it is rather simple: how to translate (in French for example) the error message which is generated automstiquement by Framework during the validation of the data.
Example of message: “The DATUM_ACTIEF_BEGIN field is required.”
I use Entity Framework to create the data model.
Thank you.
JM
ASP.NET Dynamic Data Ado.Net Entity Data Model
andreadottor
Contributor
2060 Points
312 Posts
MVP
Re: Translate Error Messages
Mar 24, 2009 01:19 PM|LINK
You can use an RequiredAttribute with specify the error message:
and you have the possibility to put the message error in the resources:http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.requiredattribute.aspx
you can specify a messagge in the attribute in this mode:
[Required(ErrorMessage = "Title is required.")]
[
Required(ErrorMessageResourceName = "Product_RequiredDescription", ErrorMessageResourceType=typeof(Resources))]The attribute must be write in the metadata class:
[ScaffoldTable(true)]
[MetadataType(typeof(ProductsMetadata))]
public partial class Products
{
}
[DisplayName("Prodotti")]
public class ProductsMetadata
{
[ScaffoldColumn(true)]
[Required(ErrorMessageResourceName = "Product_RequiredDescription", ErrorMessageResourceType=typeof(Resources))]
[DisplayName("Descrizione")]
public Object Description { get; set; }
}
Andrea Dottor
Microsoft MVP - ASP/ASP.NET
http://blog.dottor.net
ricka6
All-Star
15070 Points
2272 Posts
Microsoft
Moderator
Re: Translate Error Messages
Mar 24, 2009 07:37 PM|LINK
The current (.net 3.5 SP1) version of Dynamic Data has a bug. See Custom Validation Error message not displayed
jmvanbel
0 Points
4 Posts
Re: Translate Error Messages
Apr 06, 2009 09:24 AM|LINK
Thank you, that goes well for the messages with attribute of validation.
But there remains another problem.
For the problem of format of data, how then I can translate the following message which is posted for a field badly formatted “DateTime”: “Obligatory Field Unable to convert standard input G-string “dvdsvsdvvdsv” to “System.DateTime”.”
There is no attribute thus I cannot specify key resource!
Thank you.
JM
ricka6
All-Star
15070 Points
2272 Posts
Microsoft
Moderator
Re: Translate Error Messages
Apr 06, 2009 07:22 PM|LINK
You don't need a validation attribute - In my blog I use a non-existent attribute [DataType("dummy", -the [DataType("dummy", does not exist. Perhaps you could post your failing code. Are you having trouble setting the format string for dateTime and getting a good error message when the input cannot be converted? If you like you can post your question in another language and I'll try to get someone to translate it for me.
jmvanbel
0 Points
4 Posts
Re: Translate Error Messages
Apr 07, 2009 10:20 AM|LINK
Here my code:
[Required(ErrorMessageResourceName = "Required", ErrorMessageResourceType = typeof(Resources.ActieControle))]
[DataType(DataType.DateTime, ErrorMessageResourceName = "DateTimeInvalid", ErrorMessageResourceType = typeof(Resources.ActieControle))]
public DateTime DATUM_ACTIEF_BEGIN;
[Required(ErrorMessageResourceName = "Required", ErrorMessageResourceType = typeof(Resources.ActieControle))]
[DataType(DataType.DateTime, ErrorMessageResourceName = "DateTimeInvalid", ErrorMessageResourceType = typeof(Resources.ActieControle))]
public DateTime DATUM_ACTIEF_EIND;
And the result:
<form name="aspnetForm" method="post" action="Insert.aspx" onsubmit="javascript:return WebForm_OnSubmit();" id="aspnetForm"> <div> </div> <script type="text/javascript"> // </script> <script src="http://localhost:2742/BackOffice/WebResource.axd?d=oat1apzjGELIpuGMRFQCPg2&t=633712551647812500" type="text/javascript"></script> <script src="http://localhost:2742/BackOffice/ScriptResource.axd?d=F55QSDg5O211T5XS-85_-l3dopph-znZkV3oK_LqT4MszQhaLAeibGvG6eyxk_dNY572u3VTAheP3xKpIctLRA2&t=42654804" type="text/javascript"></script> <script src="http://localhost:2742/BackOffice/ScriptResource.axd?d=a5y0SxVR6YmdrlKfstmHFPxqBUdJVvOtW78HLTgxM3upAcclFrCZ2qcPjK-9lirP3DBNeL-J7t4kqrsJ3jhtIDcHTvYLymQYxpxin1MTS_o1&t=ffffffffa259fcd4" type="text/javascript"></script> <script type="text/javascript"> // </script> <script src="http://localhost:2742/BackOffice/ScriptResource.axd?d=a5y0SxVR6YmdrlKfstmHFPxqBUdJVvOtW78HLTgxM3upAcclFrCZ2qcPjK-9lirPbD-VNqiQJMS10B_McXPoD9x47sBysVwc8gbw1E-Ivxi9kNXexwb7Gfjm_5SEEwDp0&t=ffffffffa259fcd4" type="text/javascript"></script> <script type="text/javascript"> // </script> <div> </div> <div> <script type="text/javascript"> // </script> <div class="TitleBox"><div id="ctl00_ContentPlaceHolder1_UpdatePanel1"> <div>
The two errors message on DateTime fields are not in French!
JM
jmvanbel
0 Points
4 Posts
Re: Translate Error Messages
Apr 07, 2009 10:24 AM|LINK
A best copy/paste of the result screen:
<form name="aspnetForm" method="post" action="Insert.aspx" onsubmit="javascript:return WebForm_OnSubmit();" id="aspnetForm"> <script type="text/javascript"> // </script> <script src="http://localhost:2742/BackOffice/WebResource.axd?d=oat1apzjGELIpuGMRFQCPg2&t=633712551647812500" type="text/javascript"></script> <script src="http://localhost:2742/BackOffice/ScriptResource.axd?d=F55QSDg5O211T5XS-85_-l3dopph-znZkV3oK_LqT4MszQhaLAeibGvG6eyxk_dNY572u3VTAheP3xKpIctLRA2&t=42654804" type="text/javascript"></script> <script src="http://localhost:2742/BackOffice/ScriptResource.axd?d=a5y0SxVR6YmdrlKfstmHFPxqBUdJVvOtW78HLTgxM3upAcclFrCZ2qcPjK-9lirP3DBNeL-J7t4kqrsJ3jhtIDcHTvYLymQYxpxin1MTS_o1&t=ffffffffa259fcd4" type="text/javascript"></script> <script type="text/javascript"> // </script> <script src="http://localhost:2742/BackOffice/ScriptResource.axd?d=a5y0SxVR6YmdrlKfstmHFPxqBUdJVvOtW78HLTgxM3upAcclFrCZ2qcPjK-9lirPbD-VNqiQJMS10B_McXPoD9x47sBysVwc8gbw1E-Ivxi9kNXexwb7Gfjm_5SEEwDp0&t=ffffffffa259fcd4" type="text/javascript"></script> <script type="text/javascript"> // </script> <script type="text/javascript"> // </script>ricka6
All-Star
15070 Points
2272 Posts
Microsoft
Moderator
Re: Translate Error Messages
Apr 08, 2009 01:31 AM|LINK
Hi Ajouter,
This is a known bug. I think it might be fixed in the preview version - I'll find out tomorrow. Using the new preview 4 versions you might not need to use the work around in my blog.
To work around this bug using the current release, you need to modify DynamicData\FieldTemplates\DateTime_Edit.ascx.cs and add something like
CompareValidator1.ErrorMessage = String.Format("Date début actif {0} ", Column.DATUM_ACTIEF_BEGIN);