Writing Server Event Scripts

Description

Web publishing applications only. Server event scripts provide an opportunity to respond to or process the input from a dialog (form) web component. You can run scripts when the following events occur.

  • OnClick

    Available only for AdvancedButton objects. The OnClick script runs every time the button is clicked.

  • Initialize

    The Initialize event fires once, the first time the Form is run.

  • Validate

    The Validate event fires when a form is submitted.

  • AfterValidate

    The AfterValidate event fires after the Validate event.

  • Activate

    The Activate event fires every time the form is run.

Initialize Events

The Initialize event fires once, the first time the form is run. If the form is submitted back to itself (as is typically the case, so that the values in the Form's controls can be validated), the Initialize event is not fired. The Initialize event is typically used to set initial values for controls on the Form. If you need to execute code every time the Form is run, use the Activate event.

Validate Events

The Validate event fires when a form is submitted. Use this event to check that the value in a control is valid. If your script determines that an error has occurred, then you should set the following object properties:

CurrentControl.Has_Error = .t.
CurrentControl.Error_Message = ""

You can also use this syntax:

CurrentForm.Controls..Has_Error = .t.
CurrentForm.Controls..Error_Message = ""

If the CurrentControl.Has_Error property is ".T.", then the form will be redisplayed with the error message shown at the top of the form. The user can then make corrections and resubmit the form.

AfterValidate Events

The AfterValidate event fires after the Validate event, but only if no object on the form has had its .Has_Error property set to ".T.". A typical use of the AfterValidate event is to redirect control to another page in the application. For example:

If Condition1 = .t. Then
    Response.Redirect("Page1.a5w")
Else
    Response.Redirect("Page2.a5w")
End If

Activate Events

The Activate event fires every time the form is run. It fires after the Validate and AfterValidate events. A typical use of the Activate event is used to populate drop down list boxes on the form.

Declarations

When you display the Form Events dialog and select "Declarations" from the Event list box, you to define any User Defined Functions that you want to be available to all Xbasic event code.

You can also define functions in the code for each event handler, but these functions are local to the particular event handler.

See Also