Section 21.7. Passing Information Between Pages

21.7. Passing Information Between Pages

Every now and then, you'll want to pass a piece of information from one page to another. The master-detail page set described in the previous section uses this concept: a link on the master page not only points to the detail page, but also passes along a unique ID used to create a filtered recordset on the detail page. In other words, the master page lists a bunch of records from a database. Each record not only links to the detail page, but also passes along its unique ID. The link might be something like prodDetails.asp?prodID=7 .

The information after the ? in the URL is a URL parameter , which the detail page uses to build a recordset. In this example, the detail page would find only one recordthe one whose prodID is 7and display its details on the page. The key to the success of the master-detail page set, then, is the ability to pass information to another page and then use that information to filter a recordset (see Section 21.1.3 for details on filtering database records).

Dreamweaver can pass information to other dynamic pages using either of two tools: the Go To Detail Page and Go To Related Page server behaviors.


Note: These two tools are available only for the ASP and JSP server models. For the other server models, several developers have created extensions to fill the gap. The PHP Missing Tools extension by Felix One (www.felixone.it) includes both the Go To Detail Page and Go To Related page server behaviors for PHP. In addition, Deng Jie has created Go To Detail page extensions for ColdFusion, ASP.NET, and PHP. You can find these at the Macromedia Exchange (Section 19.2)just search for "Go To Detail Page." (These extensions work identically to the ones that come with Dreamweaver, so the following instructions still work.)

21.7.1. Go To Detail Page

A detail page, logically enough, is intended to provide more details on a single database record. To retrieve details on only one record, the detail page must include a recordset that filters the records of a database table based on some unique identifier, usually a record's primary key. For example, if every ad in a database of advertisements had its own unique ad ID, then a recordset could filter the data based on that ID number.


Note: The tutorial that starts on Section 21.8 includes an example of this server behavior in action.

The Go To Detail Page server behavior provides a way to pass information to a detail page in the URL of a linkfor example, productDetails.asp?productID=4 . In this way, when the detail page loads, it can use this URL variableproductID, in this exampleto filter the database to retrieve the requested record (see Section 21.1.5.2 for tips on using a URL variable to filter recordsets).

In many cases, you use this server behavior in conjunction with a repeating region (Section 21.3.2) on a page that lists multiple database records. In other words, you use this behavior on a master page. Then you link each record in the list to the same pagethe detail pagebut pass along a different, unique ID for each record.

To use this server behavior, first add a recordset to the page. The recordset provides the information that's passed to the detail page (usually a record's primary key). Frequently, you'll also add a repeating region, or use Dreamweaver's Repeating Table command (Section 21.3). Here's the whole process:

  1. Select an item on the page (graphic or text) to serve as a link to a detailed page .

    Since you frequently use this server behavior in conjunction with a repeating region, you could select a piece of dynamic text within the repeating region. For example, on a page that lists many products, you could select the name of the product.

  2. Make sure the Server Behaviors panel is open (Ctrl+F9 [ -F9]). Click the + button; from the pop-up menu, choose Go To Detail Page .

    The Go To Detail Page window appears (Figure 21-19). Skip the Link pop-up menu. (You can also use either the Go To Detail Page button on the Application tab of the Insert bar [see Figure 21-20] or choose Insert Application Objects Go To Detail Page to reach the Go To Detail Page window.)

    Figure 21-19. The Go To Detail Page server behavior can pass information from a recordset to another page by adding a URL parameter to a link.
    Figure 21-20. You can also apply the Go To Detail Page and Go To Related Page server behaviors from the Application tab of the Insert bar.
  3. Click Browse and select the detail page .

    You're choosing a dynamic page, of course.

    Keep in mind that this server behavior doesn't actually do anything to the detail page, like adding a recordset to it. This behavior merely links to that page, passing along some additional information in the URL. In other words, to take advantage of the data passed along in the link, you need to add a recordset to the detail page that uses the URL variable. (You can also use the URL variable in other ways, as described on Section 23.2.4.)

  4. Type a name into the "Pass URL parameter" box .

    Often, your best bet is to use the same name as the database column whose value you're using. But at the very least, the name should contain only letters and numbers , without spaces or other punctuation (because it's transmitted in the URL).

  5. From the Recordset pop-up menu, choose a recordset .

    This is the recordset containing the information to be included in the URL.

  6. From the Column pop-up menu, select a database column .

    This should be a primary-key field.

  7. If you want to pass on URL variables and form variables already present on the page, turn on the "URL parameters" and "Forms parameters" boxes .

    For a discussion of these options, read the following section.

  8. Click OK to close the window and add the link .

    Dreamweaver adds a link with all the programming that your site's server model needs.

Once you've completed these steps, open (or create) the detail page and add a recordset that uses the URL variable.

21.7.2. Go To Related Page

The other Dreamweaver tool for passing information between pages is the Go To Related Page server behavior. It takes information that's been passed to a page (in the form of URL parameters or Form parameters) and passes it on to yet another page.

Here's how you might use this feature. Suppose your Web site sells expensive manufacturing equipment. On a detail page, which lists the specifications for a particular machine, you include a link to a page with a larger photo of the machine. When the visitor clicks the "click for larger photo" link, the photo page retrieves and displays the proper photo.

But how does the photo page know which photo to display? An easy way would be to pass along the ID for the product, information that's included in the URL on the detail page.

The Go To Related Page server behavior is ideal for this situation. It simply links to another page, passing along any URL parameters or form information already processed by the page. To use it:

  1. Select the graphic or text that will serve as the link to another page .

    This could be text like "Click for larger photo," or "See a related review." Make sure the Server Behaviors panel is open (Ctrl+F9 [ -F9]).

  2. Click the panel's + button; from the pop-up menu, choose Go To Related Page .

    The Go To Related Page window appears (Figure 21-21). Ignore the Link pop-up menu.

    Figure 21-21. This server behavior links from one page to another and passes along information contained in the URL, or data that was already sent to the first page as a form.
  3. Click Browse. Select the page to which you want to pass the URL or form variables .

    In order for the linked page to take advantage of these variables, you need to add a recordset and use the variables to filter the results. You can also add these variables to your Bindings panel, as described on Section 23.2.1, and use them as dynamic text elements on the page, or even bind them to form elements.

  4. Turn on the appropriate boxes .

    The "URL parameters" box passes along any URL variables to the linked page. For example, suppose you add this behavior to a Details page, creating a link to page named moreInfo.asp . When someone comes to the detail page, the URL might be productDetails.asp?prodID=9 (depending on which record they're viewing). When the visitor clicks the link, the URL becomes moreInfo.asp?prodID=9 . In other words, the prodID=9 from the detail page is sent along to the moreInfo.asp page.

    The "Form parameters" box does the same thing for form variables. For example, when someone fills out and submits a Search form, the information travels to a Results page, which displays the results of that search. You could then preserve the form information submitted to the results page and pass it along to another page.

  5. Click OK to close the window and apply the server behavior .

    To edit one of these behaviors, double-click its name in the Server Behaviors panel; to delete one, select it in the panel and press the button or Delete.



Dreamweaver 8[c] The Missing Manual
Dreamweaver 8[c] The Missing Manual
ISBN: 596100566
EAN: N/A
Year: 2006
Pages: 233

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net