I have created a SharePoint web part that dynamically creates a user input form to enter data into a list on a public facing website and then redirect the user to another page. The code finds all editable fields for the list and then loads them into a form using BaseFieldControl to create the controls. All the fields render with a required field validator text summary underneath them if they are set as required fields. So if the user doesn't enter something for a required field then SharePoint automatically adds the text "You must specify a value for this required field." underneath the field as such:
<span class="ms-formvalidation"><span role="alert">You must specify a value for this required field.</span><br></span>
But if a field also has a validation formula set such as a formula (ValidationFormula) of =LEN(Phone)>7 and a message (ValidationMessage) of "Phone numbers must be at least 8 numbers", then the form fails validation and has a SPListDataValidationException error, not a SPFieldValidationException, and the validation message for the field does not show up on the form anywhere.
This is how I create the form:
foreach (SPField field in list.Fields)
{
BaseFieldControl editControl = field.FieldRenderingControl;
editControl.ControlMode = SPControlMode.New;
editControl.ListId = list.ID;
editControl.FieldName = field.InternalName;
editControl.RenderContext = SPContext.GetContext(HttpContext.Current, list.DefaultView.ID, list.ID, web);
panel.Controls.Add(editControl);
}
Is there anyway I can get my web part to show that custom validation message I set in the list settings in the column?
All I have been able to do is capture the more generic message that I have put in the list validation message, using SPList.ValidationMessage instead of the specific SPField.ValidationMessage.