Text box and masked text box controls provide a way to set and show their validation messages in code in case a standard regular expression validation wasn’t enough. Also the eForm code-behind offers a way to get strings localized by the currently set form’s language from the form’s resources.
Here’s an example of how to do both things.
1. Create a new form in the Designer.
2. Drop a text box control, a code block control, a combo box and a button onto a form leaving their default names NDTextBox1, NDCode1, ComboBox1 and Button1 respectively.
3. Add a new event to the NDCode1 and configure it like this:
a) Set the name of the event handler to ValidateEvent.
b) Set Button1 as the target object.
c) Select Click as the event name from the list of events.
d) Click the New button to create a new code holder.
e) When the Code Holder editor opens, replace the pre-generated code with the following:
using System; using System.Windows; using System.Windows.Controls; using Neurodot.Forms.Silverlight.Controls; using Neurodot.Forms.Silverlight.Render.Interfaces; public static class Class01 { public static void OnCustomValidate(object sender, RoutedEventArgs e) { NDTextBox txt1 = ThisForm.FindElement("NDTextBox1") as NDTextBox; // get localized error message string string errMsg = ThisForm.GetLocalizedString("$CustomValidationError"); // set one-time custom validation error message and show it txt1.SetValidation(errMsg); txt1.RaiseValidationError(); // ...and hide the validation error again txt1.ClearValidationError(); // set up permanent validation ComboBox cbx1 = ThisForm.FindElement("ComboBox1") as ComboBox; ThisForm.RegisterValidationRole( cbx1, new ComboBoxValidationRole() { ResStringName = "$ComboBox1ValidationErr", AllowNull = false, AllowFirst = false } ); } }
f) Name the code holder ValidationCode and save changes (click the Commit button).
4. Add localization to the form (chapter 8. Form Localization describes how to do that).
5. Add a custom string by clicking the Add string button, name it $CustomValidationError and set its value to text “Custom validation error message”.
6. Save the form and its localization.
7. Save or publish the form template to the Form Server and test in Render.