FirstTime

Description

Occurs the first time the page is accessed. Server-side objects are created and page variables filled before this event is triggered.

Applies to

psPage object

Arguments

None

Returns

Boolean. You must include a return value in the event script.

Usage

This event is the place to include initialization that you want to have occur only the first time the page is accessed. For example, you could use this event to call webdw.Retrieve to fetch data, or webdw.InsertRow to start off in data entry mode. It is the equivalent of the PowerBuilder Open event.

If binding is not selected for a Web DataWindow control, you should call either Retrieve or Insert in the FirstTime event. If the control is using a stateless server component and Retrieve is called once, the server automatically re-performs the retrieve, using the retrieval arguments that were passed to Retrieve during the binding phase.

NoteError processing Because this event is triggered before generation occurs, psDocument.Write cannot be used for reporting errors. Instead, you can use the ReportError method on the psPage object to trigger the ServerError event. The error will then be added to the error log, depending on the ServerError return value.

Examples

Example 1

This example adds an item to the user’s shopping cart if the value of the action page parameter (passed from a linking page) is "add". It then retrieves information from the user’s shopping cart in a DataWindow:

if (action == "add") {
  n_cart.additem(user, cd_id);
}
dw_cart.Retrieve(user);

Example 2

The following example shows code placed in the FirstTime event of a page that is loaded from a logon screen when the user enters a password that is incorrect. The showErrorsOnPage property is set to false because the error will be displayed at a precise location on the page by calling WriteErrorsToDocument in a server-side script. The error message needs to be displayed only once—in this case, at the location of the server-side script:

psPage.ReportError(myLocation, myCause, "Incorrect
		password");
psPage.showErrorsOnPage = false;

Example 3

The following example returns the value of the page variable myVar in an alert box the first time the page is accessed:

psPage.Alert (myVar + " in FirstTime event", true);
return true; 

See also