1. Understanding Server Behaviors
In contrast to
Dreamweaver's JavaScript behaviors — with their numerous required
functions and many more optional ones — a server behavior may be as
simple as one line of code. The difference, and it's a key one, is that
the code is intended to be executed by the application server, not the
browser.
Another difference
between server behaviors and JavaScript behaviors is that server
behavior code may exist outside the bounds of the HTML page. Any page
with a recordset has a section of code before the opening <html> tag, and a smaller block of code after the closing </html>
tag. Dreamweaver automatically places the code in the proper place —
and code placement is very important on the server side — when any of
its standard server behaviors are used. Dreamweaver includes more than
25 standard server behaviors; the exact number varies for each server
model. Figure 1 displays the available server behaviors for ASP.
The Server Behaviors panel
is the focal point for inserting, removing, and managing server
behaviors. Unlike the Behaviors panel, which displays only the
JavaScript behaviors attached to the selected tag, the Server Behaviors
panel displays all the server behaviors included in the current page, in
the order in which they were applied. Selecting a specific server
behavior listed in the Server Behaviors panel highlights the attached
page element, if visible in the Document window. Some server behaviors,
such as Recordset, have their own Property inspector, whereas others
display dynamic code as an attribute in a text or other Property
inspector.
Although the simplest
server behaviors can insert code without any additional user input, each
built-in server behavior has a dialog box for specifying parameters.
These vary in complexity from a single drop-down list to
multiple-section dialog boxes with every type of input element
available. As you learn in the next section, after you have inserted a
server behavior, you can easily modify its parameters.
2. Applying and Managing Server Behaviors
If you have ever completed any
Web applications in Dreamweaver, you've likely already discovered how to
apply and update a server behavior. The Server Behaviors panel is the
primary tool for inserting, modifying, and removing server behaviors.
You can display the Server Behaviors panel in several ways:
Choose Window => Server Behaviors.
Select the Server Behaviors tab from the Application panel.
Use the keyboard shortcut, Ctrl+F9 (Command+F9).
The Server Behaviors
panel remains available regardless of whether you are in Design view,
Code view, or the split-screen Code and Design view.
2.1. Inserting and removing server behaviors
To add a particular
server behavior to your page, click the Add (+) button in the Server
Behaviors panel and select the desired behavior from the list. Many of
the server behaviors have prerequisites — such as a recordset, form, or
selected element — that must be in place before they can be installed,
but these requirements vary from server behavior to server behavior. If
you attempt to insert a server behavior and some precondition has not
been met, Dreamweaver alerts you to the missing element; you are
prevented from inserting the server behavior until all the required
pieces are in place.
After you select the
server behavior from the Add drop-down list, a dialog box appears to
enable you to select or enter the needed parameters. Each dialog box is
specific to the chosen server behavior, and they vary widely in terms of
parameters offered and complexity.
Removing an existing server
behavior is simple. Select the entry for the server behavior in the
Server Behaviors panel and click the Remove (−) button. Dreamweaver
immediately removes all the associated code without requesting
confirmation.
With JavaScript behaviors,
if you delete a page element that has a client-side behavior attached,
you automatically delete that behavior. This is not always the case with
server behaviors, and it's best to always use the Server Behaviors
panel's Remove (−) button before deleting any associated text, graphics,
or form elements.
|
|
2.2. Editing the parameters
To modify the attributes
or parameters of an inserted server behavior, double-click its entry in
the Server Behaviors panel. You can differentiate between multiple
applications of the same server behavior in two ways. First, the entry
for each server behavior lists one or two of its key attributes in
parentheses. For example, a Dynamic Text server behavior applied to the LastName column in the rsMaillist recordset is displayed as follows:
Dynamic Text(rsMaillist.LastName)
Second, you can tell
which server behavior is associated with which page element by selecting
the server behavior — the associated text, graphic, or other page
element is also selected in Design or Code view.
When the dialog box
for a server behavior reopens, you can alter any of the parameters that
remain active. In some situations, as with the Go To Detail Page server
behavior shown in Figure 2,
one or more fields may be disabled and so rendered unable to be
changed. If you need to alter a disabled parameter, delete the server
behavior and reapply it.