Implementing an event

The ClientEvents property in the Properties window must be set to true (the default). The client control supports the events listed in Table 12-1. For a description of each event, see “Alphabetical list of events for the Web DataWindow client control”.

Table 12-1: Client-side events for the Web DataWindow

Event

Arguments

Return Codes

ButtonClicked

sender, rowNumber, buttonName

0 – Continue processing

ButtonClicking

sender, rowNumber, buttonName

0 – Execute action assigned to button, then trigger ButtonClicked

1 – Do not execute action or trigger ButtonClicked

Clicked

sender, rowNumber, objectName

0 – Continue processing1 – Prevent focus change

ItemChanged

sender, rowNumber, columnName, newValue

0 – Accept data value

1 – Reject data value and prevent focus change

2 – Reject data value but allow focus change

ItemError

sender, rowNumber, columnName, newValue

0 – Reject data value and show error message

1 – Reject data value with no error message

2 – Accept data value

3 – Reject data value but allow focus change

ItemFocusChanged

sender, rowNumber, columnName

0 – Continue processing

RowFocusChanged

sender, newRowNumber

0 – Continue processing

RowFocusChanging

sender, currentRowNumber, newRowNumber

0 – Continue processing

1 – Prevent focus change

About return values for DataWindow events

In client events, you can use a return statement as the last statement in the event script. The datatype of the value is number.

For example, in the ItemChanged event, set the return code to 2 to reject an empty string as a data value:

if (newValue = "") {	
   return 2;
}

ClientEvent properties

Events are implemented using ClientEvent properties that display in the Properties window for the WebDataWindowControl. To write a script for an event of the client control, find the property for the event in the left pane of the Properties window, for example ClientEventRowFocusChanging. Then select Add a New Event Handler from the drop-down list in the right pane. A JavaScript function prototype for the event handler is added to the HTML for the .aspx page.

The default name for the function is the ClientObjectName plus an underscore and then the event name:

objWDWName_eventname ( arguments )

The script is enclosed in SCRIPT tags, which are written to the HTML the first time you add an event handler. You can include client methods in the script if client scripting is enabled.

NoteUsing VBScript with JavaScript Client event scripts are inserted in JavaScript. If the page also contains some VBScript and the default page language is VBScript, you will get a Page error when you run or preview the page. You can have both JavaScript and VBScript on the page as long as the default page language is not set to VBScript.

Example

This example prevents focus from changing if the user tries to go back to an earlier row. In this case the name of the DataWindow control is dwCustomer:

<SCRIPT Language="javascript">
function objdwCustomer_RowFocusChanging(sender,
   currentRowNumber, newRowNumber)
   {
	if (newRowNumber < currentRowNumber) 
      { return 1; }
   }
</SCRIPT>

This example displays a message box informing the user which column and row number was clicked:

function objdwCustomer_Clicked(sender, rowNumber, 
   objectName)
   {
	alert ("You clicked the " + objectName + 
           " column in row " + rowNumber)
   }

For more information about when these events occur, look up the name of the associated WebDataWindowControl ClientEvent property in the Sybase DataWindow online Help in Visual Studio .NET.