How can I use a .NET CustomValidator control in my WorkflowGen web form?

A CustomValidator is similar to other .NET validator controls except that the validation process is controlled by the developers code either at the client-side or server-side.

You can build your validation code at server-side or client-side to stop the form from submitting when an entry is invalid. However, since WorkflowGen’s built-in validation is triggered at the client-side, and in order to combine the validation results to WorkflowGen’s validation dialog box without a page postback, a client-side scripted approach is suggested.

First, add a .NET CustomValidator control to your form:

<asp:CustomValidator ID="cfv" runat="server" ErrorMessage="[YOUR_CUSTOM_ERROR_MESSAGE]" Display="None" Enabled="True" SetFocusOnError="True" ValidationGroup="WFGENPage" ClientValidationFunction="[YOUR_JAVASCRIPT_FUNCTION]">

Make sure you change the error message to meet your needs. As well, the Display attribute should be set to None and the ValidationGroup attribute must be set to WFGENPage to combine your error message with WorkflowGen’s built-in message dialog box. The ClientValidationFunction attribute should be set with the name of your JavaScript function, and not a server-side method name.

Then, in your .aspx page, you can add your own JavaScript function. This function should have the following structure:

function YOUR_JAVASCRIPT_FUNCTION(source, arguments){ var ValidateResult = true; // set ValidateResult this Boolean variable to true or false based on your custom
 // validation rule; arguments.IsValid = ValidateResult; }

This JavaScript function receives the source and the arguments as parameters automatically from the CustomValidator. It returns the validation result arguments.IsValid. If the validation result is false, then the error message of your custom validator will appear in the WorkflowGen dialog box when submitting the form.

Note: Make sure your web form and WorkflowGen action meet the basic requirement for WorkflowGen built-in validation before adding the custom validator to ensure that the default validation is functioning. For more information, see My .NET validator does not trigger the validation error message.