Calling client methods

NoteSet ClientScriptable to true To write scripts that call methods of the client control, the ClientScriptable property in the Properties window or in DataWindow Designer must be set to true—the default is false. If this property is not set, you receive the error: Object doesn't support this property or method.

Several client methods accomplish the same tasks as actions of Button controls. If your DataWindow object uses Button controls to implement scrolling and updating, you might not need to do any client scripting.

You can use the methods in the first column in Table 12-2 on the client in client-side events or functions. Methods marked with an asterisk force the Web page to be reloaded. The second column lists the properties and methods that perform the same function in a DataWindowControl or the server WebDataWindowControl.

For a description of each client method, see “Alphabetical list of methods for the Web DataWindow client control”. For a description of the properties and methods in the second column, see the Sybase DataWindow help in Visual Studio .NET.

Table 12-2: Methods for the Web DataWindow client control

Client control method

DataWindow control equivalent

AcceptText

AcceptText method

DeletedCount

DeletedCount property

DeleteRow *

DeleteRow method

GetClickedColumn

ObjectUnderMouse.GOB property

GetClickedRow

ObjectUnderMouse.RowNumber property

GetColumn

GetColumn method

GetItem

GetItem* methods

GetItemStatus

GetItemStatus and GetRowStatus methods

GetNextModified

FindNextModifiedRow method

GetRow

CurrentRow property

InsertRow *

InsertRow method

IsRowSelected

IsSelected method

ModifiedCount

ModifiedCount property

Retrieve *

Retrieve method

RowCount

RowCount property

ScrollFirstPage *

ScrollFirstPage method (on WebDataWindowControl)

ScrollLastPage *

ScrollLastPage method (on WebDataWindowControl)

ScrollNextPage *

ScrollNextPage method (on WebDataWindowControl)

ScrollPriorPage *

ScrollPriorPage method (on WebDataWindowControl)

SelectRow

SelectRow method

SetColumn

SetColumn method

SetItem

SetItem methods

SetRow

SetRow method

SetScroll

ScrollNextPage and ScrollPriorPage methods (on WebDataWindowControl) and ScrollToRow method on DataWindowControl

SetSort

SetSort method

Sort *

Sort method

Update *

UpdateData method

NoteGetNextModified The GetNextModified method finds modified rows in the current page only.

This function in the script area of a Web form’s .aspx page updates data:

function btnUpdate_onclick() {
   objdwCustomer.Update();
}

The button is defined in the form:

<form id = "Form1" method="post" runat="server">
   <INPUT language="javascript" id="btnUpdate"
      type="button" value="Update" 
      onClick="return btnUpdate_onclick">
   ...
</form>

Note that you can get the same functionality with the Update action for a Button control in the DataWindow object. For more information, see “Using Button and Picture controls”.

Handling method failures

The methods marked with an asterisk in Table 12-2 cause an action to be posted back to the server. Whenever an action is posted back to the server, the server-side BeforePerformAction event is fired before the action is performed, enabling the user to cancel the action, and the AfterPerformAction event is fired after the action is performed.

These methods always return 1 unless the AcceptText method that is called implicitly after each method is called fails. Use the AfterPerformAction event to test whether the action was performed successfully. The AfterPerformAction event handler has two arguments. The Action argument indicates the type of the postback action, for example ScrollNextPage, InsertRow, or Retrieve. These actions can be posted from buttons in the DataWindow object as well as from client script. The ActionResult argument indicates whether the action succeeded.

The following example in the code file for a form writes the result of an action to a text box called txtMsg:

[Visual Basic]
Private Sub dw_1_AfterPerformAction(ByVal sender As  _
   Object, ByVal e As   _
   Sybase.DataWindow.Web.AfterPerformActionEventArgs)_
   Handles dw_1.AfterPerformAction

   txtMsg.Text = "AfterPerformAction: " +  _
     e.Action.ToString + " " + e.ActionResult.ToString
End Sub

[C#]
private void wdw_afteraction(object sender, Sybase.DataWindow.Web.AfterPerformActionEventArgs e)
{
   this.txtMsg.Text = this.txtMsg.Text +
      "AfterPerformAction: " + e.Action.ToString() + 
      " " + e.ActionResult.ToString();
}

Note that client-side methods do not throw DbErrorExceptions, so you might choose to use server-side methods to obtain better information about database errors.