Server Side Validation and ASP pages

1 minute read time.
If you need to perform some server side validation within an ASP page that would use the standard CRM behaviour to highlight the field that contains the invalid data. Then the simplest approach is to use Validation Rules.

These can be defined either at the level of the screen or applied to a screen within the code of the ASP page.

The basic structure of a Validation rules looks like this:

//////////

if (Values("field_name")!=strExpectedValue)
{
Valid = false;
ErrorStr = "Error Message Goes Here"
}

//////

Valid when set to false will return the screen to edit mode and will indicate the offending field to the user. The field is marked with a a red star and the contents of the ErrorStr is written out.

The Values("field_name") collection allows you to access the submitted fields.

If you define the Validation rule in meta data (in the screen defination) e.g. in the companyboxlong screen then wherever this screen is used then the rule will be applied.

If you only want to add a rule to a screen in an ASP page this can be done using the field properties.

E.g.

var myEntryBlock = myBlock.GetEntry("field_name"); //myBlock is the screen
with (myEntryBlock)
{
ValidateScript = "if (Values('field_name')";
}