This topic is locked

Date validation < current date in ASPRUNNER.NET project

7/22/2022 6:27:59 PM
ASPRunner.NET General questions
R
Rajesh author

Hi,
I want to validate a date field in an add/edit page to be not a future date. Any example of ASPrunner.NET would help.

Thanks

Raj

Here is what I have and its not working. (Error: include\ISJnd_TableEvents.cs(58,36): error CS1012: Too many characters in character literal [X:\NetRunnerPagesStaging\App\InterpreterServices\output\InterpreterServices.csproj])

currently testing in beforerecordadded event (code follows)

MVCFunctions.Echo("start");
var di = Runner.getControl(pageid, 'DateTimeInputStarted');
if (di.getValue()> now())
{
MVCFunctions.Echo("failure");
//var message = "failure message";
//ctrl.setMessage(message);
//return false;
}
else
{
MVCFunctions.Echo("success");
//return true;
}

Pete K 7/22/2022

It looks like you're mixing JavaScript with server-side code (C#). Is this code in a client-side or server-side event? For validation, you want to use Javascript and put it in the OnLoad event. See the documentation under JavaScript API > Control Object.

T
Tuong Do 8/11/2022

If you want to validate at the server level then

In the Before record updated event (Assuming VISIT_DATE is the field name)

if ( DateTime.Parse(values["VISIT_DATE"]) > DateTime.Today) {
message = "Visit date can not be a future date " ;
return false ;
}

R
Rajesh author 8/12/2022

Here is what I am using currently and its working (partially)

  1. field event , client before (javascript)

var ctrl = Runner.getControl(pageid, 'DateTimeInputStarted');
ctrl.setAllowedInterval( null, moment(), 'Future Date is not Allowed' );
(this prevents future date based on date only (time not included).

  1. 'before record added' event (C#)

// Prevents a future date entry in DateTimeInputStarted - server validation
DateTime inputdate=DateTime.Parse(values["DateTimeInputStarted"]);
if (inputdate > DateTime.Now)
{
message="Can not use future date for 'Date Time Input Started'";
return false;
}
return true;
(this prevents future date including time)

TIA