What is the Error property of the InputField class used for?

Sep 15, 2010 at 2:21 PM


When I give this property a value, then the Error is shown as soon as the form is rendered. Can it be that this property should be used for server-side validation, and not be set initially?



Sep 15, 2010 at 2:51 PM

The Error property contains an error message that the end user sees in their browser and is typically set by the InputField.Validate() method.

Each InputField class has a property called RequiredMessage, which you should set if the field is required. When Validate() gets called, if the field is required but has no input, RequiredMessage will be copied to the Error property. Similarly, classes that derive from TextField (Textbox and Textarea) have a RegexMessage property that holds an error message if the Regex doesnt match the user's input.

Another way you can use the Error property is to set it manually when you do more complex validation in the Validated event, which each InputField exposes. Look at the Demo Project Models/FormProvider.cs for an example (look at the FileUpload field and it's Validated event handler.


Hope this helps.