Calling a Custom Function When a Button is Clicked

You can call custom code functions of your own when a button is clicked.  The invoked code is typically placed in the associated page’s customizable code-behind class (details about this are found elsewhere in the online help).  To “catch” the function call, override the OnApplicationEvent function.

Group

Property

Setting

Button Actions

Actions

Custom

Appearance

Text

Export to PDF

Behavior

CausesValidation

No

Behavior

CommandName

DisplayAsPDF

For example, a button might call a custom function called “ExportToPDF” which is invoked when the button is clicked.  The OnApplicationEvent function implements an event handler that is called when the new “Export to PDF” button is clicked.  In this example, the DisplayReportAsPDF function connects to the data base, populates the report, and then displays it in the web browser.

Visual Basic .NET:

' This method handles the ApplicationEvent produced by the ExportToPDF button

Public Overrides Sub OnApplicationEvent(ByVal args As BaseClasses.ApplicationEventArgs)

 

     ' Handle the custom "DisplayAsPDF" command, but pass others off to the base class

     If args.EventType = BaseClasses.ApplicationEventArgs.EventTypes.Custom AndAlso _

          args.CustomEventName = "DisplayAsPDF" Then

          '' create the report object and produce the report

          Dim crReportDocument As New ProductsList()

          DisplayReportAsPDF(crReportDocument)

     Else

          ' not the custom "DisplayAsPDF" command, pass it on

          MyBase.OnApplicationEvent(args)

     End If

End Sub