locked
Integer validation not working on asp.net dynamic data RRS feed

  • Question

  • User-1759624489 posted

    Hello, I have this code for some integer columns.  But when I type for example a letter on the field I got an error message in English not the message in spanish "El campo debe ser  un entero positivo".

     

    Am I missing something?

     

     [DisplayName("Metros Cuadrados")]
            [DataType("Int32", ErrorMessage="El campo debe ser  un entero positivo")]
            [Required(ErrorMessage="Este campo es requerido.")]
            [Range(0, int.MaxValue, ErrorMessage = "El valor debe ser un entero positivo")]
             public object SquareMeters { get; set; }

    Wednesday, September 17, 2008 5:47 PM

All replies

  • User-797310475 posted

    What is the English error message that you are getting?

    Wednesday, September 17, 2008 7:56 PM
  • User-1005219520 posted

    I just applied your attributes to the SalesOrderDetails table of AWLT08 and got the following on entering a while editing

    Edit entry from table SalesOrderDetails

    List of validation errors
    • The field Metros Cuadrados must be a valid Integer.
    • El valor debe ser un entero positivo
    Metros Cuadrados <INPUT class=droplist id=ctl00_ContentPlaceHolder1_DetailsView1___OrderQty_TextBox1 size=10 value=a name=ctl00$ContentPlaceHolder1$DetailsView1$__OrderQty$TextBox1> Este campo es requerido. The field Metros Cuadrados must be a valid Integer. El valor debe ser un entero positivo
     
    and for inserting

    Add new entry to table SalesOrderDetails

    Metros Cuadrados <INPUT class=droplist id=ctl00_ContentPlaceHolder1_DetailsView1___OrderQty_TextBox1 size=10 value=a name=ctl00$ContentPlaceHolder1$DetailsView1$__OrderQty$TextBox1> Este campo es requerido. The field Metros Cuadrados must be a valid Integer. El valor debe ser un entero positivo

    Perhaps you have a name mismatch on your partial class? Can you apply    [ScaffoldColumn(false)] to verify you have the correct entity name? Here is what I used

    [MetadataType(typeof(SalesOrderDetailMetaData))]
    public partial class SalesOrderDetail { }
    
    public class SalesOrderDetailMetaData{
    
        [DisplayName("Metros Cuadrados")]
        [DataType("Int32", ErrorMessage = "El campo debe ser  un entero positivo")]
        [Required(ErrorMessage = "Este campo es requerido.")]
        [Range(0, int.MaxValue, ErrorMessage = "El valor debe ser un entero positivo")]
    
        public object OrderQty { get; set; }
    }
     

    You can also make the following change (translation by babel)

    <asp:ValidationSummary ID="ValidationSummary1" runat="server" EnableClientScript="true"

    HeaderText="Lista de errores de la validaci¢n" />

    Thursday, September 18, 2008 3:05 AM
  • User660823006 posted

    Couple of questions I would have. By default our FieldTemplates have their own CompareValidator in them which will have default error messages based on the localized version of the framework. Since you are getting default english errors this would indicate to me that you are using an english version of the .NET 3.5 Framework. Marcin, if you install an english version of the Framework how would you change our default error messages to another langauge?

    Thursday, September 18, 2008 1:57 PM
  • User-1759624489 posted

    I am getting this english error.

     

    The field Metros Cuadrados must be a valid Integer.

     

    I checked the validators on the integer_edit and they dont have a message set up on them

     

    <%@ Control Language="C#" CodeFile="Integer_Edit.ascx.cs" Inherits="Integer_EditField" %>

    <asp:TextBox ID="TextBox1" runat="server" Text="<%# FieldValueEditString %>" Columns="10" CssClass="textfield"></asp:TextBox>
    <asp:RangeValidator runat="server" ID="RangeValidator1" CssClass="droplist" ControlToValidate="TextBox1" Type="Integer"
        Enabled="false" EnableClientScript="true" MinimumValue="0" MaximumValue="100" Display="None" />
    <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator1" CssClass="droplist" ControlToValidate="TextBox1" Display="None" Enabled="false" />
    <asp:CompareValidator runat="server" ID="CompareValidator1" CssClass="droplist" ControlToValidate="TextBox1" Display="None"
        Operator="DataTypeCheck" Type="Integer" ErrorMessage="El campo debe ser un númeo entero válido."/>
    <asp:RegularExpressionValidator runat="server" ID="RegularExpressionValidator1" CssClass="droplist" ControlToValidate="TextBox1" Display="None" Enabled="false" />


    <ajax:ValidatorCalloutExtender  runat="server" ID="ValidatorCalloutExtender1"  Enabled="true"  TargetControlID="RangeValidator1"></ajax:ValidatorCalloutExtender>
    <ajax:ValidatorCalloutExtender  Enabled="true" runat="server" ID="ValidatorCalloutExtender2"   TargetControlID="RequiredFieldValidator1"></ajax:ValidatorCalloutExtender>
    <ajax:ValidatorCalloutExtender  runat="server" ID="ValidatorCalloutExtender3"   TargetControlID="CompareValidator1"></ajax:ValidatorCalloutExtender>
    <ajax:ValidatorCalloutExtender  runat="server" ID="ValidatorCalloutExtender4"   TargetControlID="RegularExpressionValidator1"></ajax:ValidatorCalloutExtender>


    <asp:DynamicValidator runat="server" ID="DynamicValidator1" CssClass="droplist" ControlToValidate="TextBox1"  Enabled="true" Display="None" />

    Thursday, September 18, 2008 2:06 PM
  • User-1005219520 posted

    Hi levalencia,

    The DataType attribute is not used to to set the error message. You use the DataType attribute to set a more specific data type (for example URL is a sub-type of string). You can read about it here. The CLR data type comes from the data model. For the AWLT DB, SalesOrderDetails table

      <Column Name="OrderQty" Type="System.Int16" DbType="SmallInt NOT NULL" CanBeNull="false" />

     You can read how this attribute is used in How to: Customize Data Field Appearance and Behavior For Non-Intrinsic Data Types in the Data Model

    Hopefully Marcin can explain how to localize the default error messages.

    Thursday, September 18, 2008 5:14 PM
  • User-1759624489 posted

    I havent been able, I tried this

       [DisplayName("Metros Cuadrados")]
            [DataType("Int32", ErrorMessage="xx")]
            [Required(ErrorMessage="Este campo es requerido.")]
            [Range(0, int.MaxValue, ErrorMessage = "El valor debe ser un entero positivo")]
             public object SquareMeters { get; set; }

     

    but when I type a character it says the english error again

     

     

    Thursday, September 18, 2008 7:09 PM
  • User660823006 posted

    As I mentioned earlier in this thread the error messages you are seeing are the default error messages that are part of Dynamic Data and they are firing from the asp:CompareValidator that is in the field template control. If you are running a localized version of the .NET 3.5SP1 framework these will be in the langauge of the localization. If not we will need to wait for Marcin to respond on how to change the default error messages. None of those attributes you are sticking on the fields change the default error message for the CompareValidator.

    Thursday, September 18, 2008 8:30 PM