Before the .NET target is deployed, you can code client-side events in JavaScript and set properties to reference the JavaScript code that handles client-side events.
You must set the properties in #IF DEFINED -#END IF conditional compilation code blocks for .NET targets. The beginning and end tags for these code blocks signal the PowerBuilder native compiler to ignore the code contained inside them.
The code inside the conditional compilation code blocks is passed to the Web browser client from the server at runtime. You use this code to designate JavaScript functions that handle events on client-side objects. Most events on client-side objects cause a postback to controls on the server side, because the events have server-side analogs that are written originally in PowerScript, then transformed to run in the .NET environment.
If you write any JavaScript code for the client-side events, the postback to the server is interrupted. To resume a postback, you can call the submit method for Web Forms or one of the postback methods generated in the PBDataWindow.JS file. The PBDataWindow.JS file is generated in the Scripts subdirectory of the main project directory under the IIS virtual root.
The postback methods of the PBDataWindow.JS file are described in Default Event Handlers.
Properties of the DataWindow class allow you to handle client-side events in JavaScript code. The JavaScriptFile property specifies the JS file that contains JavaScript functions for handling individual client-side events.
#IF Defined PBWEBFORM THEN dw_1.JavaScriptFile = “D:\Scripts\MyScriptFile.js” #END IF
See Alphabetical Liist of Web DataWindow Client-Side Events.
To specify a JavaScript function for handling a client-side event, you must indicate the function to call in the corresponding Web DataWindow property. The name of the corresponding property consists of the name of the client-side event with an "OnClient" prefix. For example, the property corresponding to the ItemChanged event is OnClientItemChanged.
#IF Defined PBDOTNET THEN dw_1.JavaScriptFile = “D:\Scripts\MyScriptFile.js” dw_1.OnClientClicked = “MyDWClickedEventHandler” #END IF
The script for the MyDwClickedEventHandler event handler must use the syntax for the client-side Clicked event described in Clicked.
The OnClientClick CommandButton property specifies a snippet of JavaScript code that executes when a command button is clicked.
#IF DEFINED PBWEBFORM THEN cbx_1.AutoPostBack = false #END IF
For more information on the built-in Web Forms control properties, see Web Forms Properties.