Although the .NET form script event handler "AfterOpen" can be used to retrieve data and prefill a form, it is only executed when a new form template is downloaded to an iOS or Android device, or web browser. ( This setting is available on the administrative web interface of the Mi-Forms Server by editing a form template and setting "run .NET AfterOpen event on sync" to Yes. )
To execute .NET code on the Server whenever a form is opened on an iOS or Android device, or web browser, use the contactServer() JS api to send a command to the Server from within the MFAfterOpen event handler in JavaScript. The .NET form script event handler serverContacted() will process the command and return any data as needed.
In this example, see both JS form script and .NET form script. The following occurs:
On JavaScript based Client:
1. MFAfterOpen will run whenever form is opened.
2. MFAfterOpen runs contactServer which sends a command "DateTimePlease" to the server...
On .NET based Server:
3. ServerContacted will accept the "DateTimePlease" command and return a server response accordingly.
On JavaScript based Client:
4. The success callback function of the contactServer api will accept the server response and display the results.
Although the example simply retrieves the current date and time, the server-side code could possibly reach out to an internal resource such as a database.