Bindings Page 7
August 7,2002
The Bindings tab of the Applications panel holds dynamic content in
a safe place for you to easily access and bind as you build your documents.
For example, when you create a recordset, it will be listed under the Server Behaviors tab, and accessible under
the Bindings tab. You will be able
to bind recordset columns into your document (see the Server Behaviors
section of this chapter for more on recordsets).
Recordsets are not the only dynamic content you can store
in the Bindings area; you can also store other dynamic text such as Request
Variables, Session Variables, and Application Variables. Request Variables
include cookies, querystrings, form variables, and environment variables.
(If you need a refresher on Request and Session Variables, see Chapter 5.)
Bear in mind that the Bindings area does not create the variables for you. It simply
allows you to store dynamic variables you have already created throughout
your applications so that you can access them easily as you build documents.
For example, the Log In Server Behavior
creates a session variable named MM_Username that holds the username of a successful login. You can then add MM_Username to the bindings area so you can use it with ease on any documents
you create.
Request Variables
Now let's test some dynamic variables and store them in
the Bindings tab, so we can get a
feel of how this all works. To start off with, we will look at Request variables.
Request.QueryString
Create a new dynamic ASP web page and save it as create_request_variables.asp. Add the following code to the body of your page:
<a href="create_request_variables.asp?my_id=23&my_name=omar">create query_strings</a>
When this link is clicked two
query strings will be passed: my_id and my_name. Store these variables in the Bindings
area by selecting Bindings, then Request Variables (this can be found
in the menu underneath the + button). Select Request.QueryString from the Type
menu and type my_id in the Name
field. Click OK. You will now see the my_id variable listed under Request
in the Bindings
window.
Follow the same steps to also add the my_name querystring and it will be added to the Request list.
Now we can start using and reusing our dynamic variables
wherever we want – drag and drop them from the Bindings
window anywhere you like in your document, and Dreamweaver MX will generate
the ASP code to display the variables. For example, if we drag one instance
of each variable we created above into create_request_variables.asp, our code will now look like this:
<a href="create_request_variables.asp?my_id=23&my_name=omar">create query_strings</a>
<%= Request.QueryString("my_name") %>
<%= Request.QueryString("my_id") %>
Now if we load our page up in a browser and click the hyperlink,
the values of the parameters should appear wherever you placed them on your
page:
Go back to the code. Create a form and place one textfield
and a hidden field inside the form. In Design View, select the textfield and
then from Bindings select the my_name querystring variable. Finally click the Insert button at the bottom of the Bindings window – this will bind the my_name querystring variable as the value of the <textfield> element. Do the same to bind the my_id querystring variable to the hidden field. When this page is viewed
live and the querystrings are passed, the textfield and hidden form elements
will be populated with the querystring variables.
This tactic may be used to maintain state between pages
by passing data held as querystring variables inside a form. Of course, instead
of the form, you could create another hyperlink and simply pass the current
querystrings to a second page. These methods are often used to pass data from
page to page, because remember that, unlike sessions and cookies, querystrings
and form elements cannot be retrieved on a page unless they are manually passed
from a prior page. As a note, they can be passed from the same page too.
Dreamweaver MX makes it easy to reuse the dynamic querystring
variables on pages throughout our site. After adding them to Bindings, we
can simply drag and drop them from the Bindings window. Henceforth instead
of typing out <%=Request.QueryString("querystring_name")
%> when you click the Request Variable
option from Bindings, you see that
there are other request variable types besides querystrings. We can store
those request variables in the Bindings window just as we have with querystrings.
Data Source Name (DSN) - Page 6
Dynamic Dreamweaver MX
Request.Form - Page 8
|