Skip to main content

Calling Server Side Methods

Next, we surround the image with an anchor tag so that we can specify the functionality that we want to be invoked when a user clicks on the image. In this case, we do not want to display a new page, so we set the tag's href attribute to “.”.

When the user clicks on the image—in HTML parlance, when an “onClick” event occurs— we want some code to execute. We specify the code to execute using the onClick attribute of the <a> tag. Typically, this attribute contains JavaScript code that will run in the browser.

Here, though, we do something different: we use the

#server( ... )#

syntax to run code on the Caché server instead.

Note that we append the JavaScript code ";return false;" to the end of our attribute value to prevent the browser from attempting to follow the link defined by the href attribute. This is a standard JavaScript technique used when hyperlinks invoke functions.

—ShowTimes.csp—
ShowTimes.csp
<html> <body>
<csp:class encoded=1 super="%CSP.Page,Cinema.Utils">
<csp:query 
        name="Times" 
        classname="Cinema.Show" 
        queryname="ShowTimes"
        P1='#(%request.Data("FilmID",1))#'>
        
<csp:object 
        name="Film" 
        classname="Cinema.Film" 
        objid='#(%request.Data("FilmID",1))#'>

<font> <b>Today's Show Times for #(Film.Title)#</b></font>

<table cellpadding=5> <tr> ... </tr>
<csp:while condition="Times.Next()">
    <tr>
    <td>#(Times.Get("StartTime"))#</td>
    <td>#(Times.Get("TheaterName"))#</td>
    <td align="center">
    <a href=. onClick="#server(..AddShow(#(Times.GetData(1))#))#;return false;">
    <img src="Tickets.gif" width="130" height="39" border="0" 
    alt="Click to order tickets for this show">
    </a>

    </td>
    </tr>
</csp:while>
</table>
</body> </html>
FeedbackOpens in a new tab