Information Lookups via ASP Pages

Earlier in this appendix you learned how to create smart tag actions that navigate to a specific web site when a user enters a term that is stored in the XML term list. Instead of sending users to public or commercial web sites, you may want to program actions that link to your own ASP pages and return appropriate data from your database. The XML smart tag list description file can call the ASP script and pass to it the required term to look up, as well as other arguments that you may find necessary for your script. To illustrate how you can provide information lookups via ASP pages, let's create a new XML smart tag list description file that will display information related to some customers in the Northwind database. We will call this new smart tag Customer Information. Figure C-3 displays smart tag actions that we will implement for this smart tag.

gSDuH

hhb;

A 1

B

C

D

E

F1

1

7

3

Customer Id

_____

J

ALFK1 \

|® T[

5

ANTON „

Customer Information

5

QUEEN , ULAS d

View Customer Full Name

7

8

FRANK j

View Country Name Check Lq&I Ord« Date

■3

to

Remove thes Smart Tag

11

12

Smart Tag Options...

13

[J

| < 4 > >[ ShCCtl

' SheetZ / 5heet3 /

h

1

This custom smart tag will access data from the Northwind database.

Figure C-3:

This custom smart tag will access data from the Northwind database.

1. Open Notepad and prepare the XML document shown in Figure C-4. When you are done, save the file as Customer.xml in the C:\Program Files\Common Files\Microsoft Shared\Smart Tag\Lists folder.

Note: The next few steps will walk you through setting up a virtual directory on your computer. You will use this directory to store your ASP script, which you will prepare later. For more information on creating virtual directories and Active Server Pages (ASP), refer to Chapter 16 of this book.

2. Create a new folder on your computer named C:\Inetpub\www-root\SmartTags.

3. Right-click the C:\Inetpub\wwwroot\SmartTags folder name and choose Properties.

4. In the Properties dialog box, click the Web Sharing tab.

5. Click the Share This Folder option button and click the Add button.

6. In the Alias text box, enter Tags as the name of your virtual directory. The Edit Alias dialog box should have the Read Access permission and Scripts Application permission selected. Click OK to exit the Edit Alias dialog box.

7. Locate the Northwind.mdb file on your computer and copy it to the C:\Inetpub\wwwroot\SmartTags folder.

Figure C-4: The XML smart tag list definition file can link to ASP script.

The XML code shown above uses the same elements as the State Explorer smart tag that you prepared in an earlier example. This time, however, the termlist contains the customer IDs that you would like to look up in a database on your server. Because the customer IDs are not enclosed in double quotes, they will be recognized whether they are typed in upper- or lowercase letters. Let's take a closer look at the defined actions because they differ a bit from what you've seen in the State Explorer smart tag. To query a database, you need to reference your ASP script in the URL element, as follows:

<FL:action id="NameLookup"> <FL:caption>View Customer Full Name</FL:caption> <FL:url>http://localhost/tags/getInfo.asp?Term= _ {TEXT}&amp;ActionId=NameLookup</FL:url> </FL:action>

The above code will execute the getlnfo.asp script (which is located in the virtual directory named tags on the local server) upon selection of the View Customer Full Name option from the Smart Actions menu. The code of the getlnfo.asp script is shown below. Notice that this script file expects two parameters that are provided at the end of a URL following the "?" character. The first parameter will pass the customer ID, and the second one will pass the action ID. The action ID will allow the script to decide which SQL statement should be run to return the data. This way, you can have one Active Server Page handle all of your smart actions. Recall that when you pass parameters to ASP pages, they are separated by the ampersand (&). In your XML code, however, to ensure proper parsing and interpretation, the parameters must be separated by "&amp;" like this:

<FL:url>http://localhost/tags/getInfo.asp?Term={TEXT} _ &amp;ActionId=NameLookup</FL:url>

When you call the ASP page, the URL will be parsed as follows:

http://localhost/tags/getInfo.asp?Term=ALFKI&ActionId=NameLookup

8. Open Notepad and prepare the ASP script file shown below. When you are done, save the file as getlnfo.asp in the C:\Inetpub\wwwroot\ SmartTags folder.

0 0

Post a comment