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.
For more information, see “About conditional compilation”.
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 Chapter 3, “Client-Side Events and Default Event Handlers.”
DataWindow property for setting a customized event handler 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. Make sure to deploy the JavaScript file that contains your customized event handling code. You assign the JavaScriptFile property in an #IF DEFINED -#END IF code block:
#IF Defined PBWEBFORM THEN
dw_1.JavaScriptFile = “D:\Scripts\MyScriptFile.js”
#end if
DataWindow properties for calling client-side events The following DataWindow events can be handled on the client side in JavaScript code:
Clicked
ButtonClicking
ButtonClicked
DoubleClicked
ItemChanged
ItemError
ItemFocusChanged
RButtonDown
RowFocusChanged
RowFocusChanging
For more information on client-side events, see Chapter 3, “Client-Side Events and Default Event Handlers.”
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.
The following example references a script called MyDwClickedEventHandler for the client-side DataWindow Clicked event. The script for the MyDwClickedEventHandler event handler must use the syntax for the client-side Clicked event described in Chapter 3, “Client-Side Events and Default Event Handlers.”
#IF Defined PBDOTNET THEN
dw_1.JavaScriptFile = “D:\Scripts\MyScriptFile.js”
dw_1.OnClientClicked = “MyDWClickedEventHandler”
#END IF
Client-Side CommandButton property The OnClientClick CommandButton property specifies a snippet of JavaScript code that executes when a command button is clicked.
AutoPostBack You can reduce postbacks and increase performance by setting the AutoPostBack property for CheckBox and RadioButton controls to false.
#IF DEFINED PBWEBFORM THEN
cbx_1.AutoPostBack = false
#END IF
For more information on the built-in Web Forms control properties, see Chapter 6, “Properties for .NET Web Forms.”