Microsoft KB Archive/928702

From BetaArchive Wiki
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Article ID: 928702

Article Last Modified on 12/6/2006



APPLIES TO

  • Microsoft Expression Web



INTRODUCTION

This article describes how to use Active Server Pages (ASP) pages to complete mathematical calculations in a form before you send data to a database in Microsoft Expression Web.

MORE INFORMATION

In a Expression Web Web site, you may want to calculate data in a Web page and then send that data to a database. For example, you may want to automatically calculate a total that is based on values that are entered by the user and then send that total value to a database.

There are several ways to perform this kind of calculation. One of the easiest ways is to use simple ASP pages.

To create ASP pages that calculate and submit a total to a database, follow these steps.

Step 1: Create the ASP pages in Expression Web

To do this, follow these steps:

  1. Start Expression Web.
  2. On the File menu, point to New, and then click Page.
  3. Click HTML, and then click OK.
  4. On the File menu, click Save.
  5. In the Save As dialog box, type input.asp, and then click Save.
  6. On the File menu, point to New, and then click Page.
  7. Click HTML, and then click OK.
  8. On the File menu, click Save.
  9. In the Save As dialog box, type send.asp, and then click Save.

Step 2: Modify the Input.asp page

The purpose of the Input.asp page is to gather the values to be calculated by providing input boxes for the user. The user types the values in the input boxes and then clicks a button. Input.asp then submits this information to the Send.asp page for processing.

To modify the Input.asp page, follow these steps:

  1. In Expression Web, click the Input.asp file.
  2. In the Toolbox section, drag a Form control to the page.
  3. In the Toolbox section, drag an Input (Text) control to the page.
  4. Right-click the text box, and then click Form Field Properties.
  5. In the Text Box Properties dialog box, type number in the Name box, type 100 in the Width in characters box, and then click OK.
  6. In the Toolbox section, drag an Input (Text) control to the page.
  7. Right-click the text box, and then click Form Field Properties.
  8. In the Text Box Properties dialog box, type cost in the Name box, type 100 in the Width in characters box, and then click OK.
  9. Right-click the form, and then click Form Properties.
  10. In the Form Properties dialog box, click Send to other, and then click Options.
  11. In the Options for Custom Form Handler dialog box, type send.asp in the Action box.
  12. In the Method list, click post, and then click OK two times.

When the Input.asp page is viewed in HTML, it resembles the following page:

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 1</title>
</head>

<body>

<form method="POST" action="--WEBBOT-SELF--">
    <!--webbot bot="SaveResults" u-file="A:\_private\form_results.csv" s-format="TEXT/CSV" s-label-fields="TRUE" startspan --><input TYPE="hidden" NAME="VTI-GROUP" VALUE="0"><!--webbot bot="SaveResults" endspan i-checksum="43374" -->
    <p><input type="text" name="number" size="100"><input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></p>
</form>
<form method="POST" action="send.asp">
    <p><input type="text" name="cost" size="100"><input type="submit" value="Submit" name="B3"><input type="reset" value="Reset" name="B4"></p>
</form>

</body>

</html>

Step 3: Modify the Send.asp page

The Input.asp page sends the values that are to be calculated to the Send.asp page. Send.asp finishes the calculation and then submits the calculated total to the database.

To modify the Send.asp page, follow these steps:

  1. In Expression Web, click the Send.asp file.
  2. Click the Code tab on the bottom of the page to switch to HTML view.
  3. Copy the following code, and then paste it above the initial "<html>" tag at the top of the page:

    <%
    dim n, c, t
    n = request("number")
    c = request("cost")
    t = c*n
    %>
  4. Click the Design tab on the bottom of the page to switch to normal view.
  5. In the Toolbox section, drag a Form control to the page.
  6. Click the Code tab on the bottom of the page to switch to HTML view.
  7. Copy the following code, and then paste it immediately after the "<form method="POST" action="--WEBBOT-SELF--">" tag:

    Thanks for the information. You input <%=Server.HTMLEncode(n)%> for the quantity, and  <%=Server.HTMLEncode(c)%> for the cost. If this is correct, click Submit. 
  8. Click the Design tab on the bottom of the page to switch to normal view.
  9. Right-click the form, and then click Form Properties.
  10. In the Form Properties dialog box, click Advanced.
  11. In the Advanced Form Properties dialog box, click Add.
  12. In the Name/Value Pair dialog box, type cost in the Name box, and then type <%=c%> in the Value box.
  13. Click OK.
  14. In the Advanced Form Properties dialog box, click Add.
  15. In the Name/Value Pair dialog box, type number in the Name box, and then type <%=n%> in the Value box.
  16. Click OK.
  17. In the Advanced Form Properties dialog box, click Add.
  18. In the Name/Value Pair dialog box, type total in the Name box, and then type <%=t%> in the Value box.
  19. Click OK two times.
  20. In the Form Properties dialog box, click Send to database (Requires FrontPage Server Extensions), and then click Options.
  21. In the Options for Saving Results to Database dialog box, click Create Database, and then click OK in the confirmation dialog box that appears.
  22. In the Options for Saving Results to Database dialog box, click the Saved Fields tab.

    Notice that three database columns are created. These columns map to the number, cost, and total form fields from the ASP pages.
  23. Click OK two times.
  24. Save both pages.
  25. To publish the pages, click Publish Site on the File menu.
  26. In the Publish Destination dialog box, type the URL of the server, and then click OK.
  27. Test the pages, and then verify that the values and the total are inserted in the database.


REFERENCES

For more information about how to use databases and ASP pages together with FrontPage, click the following article numbers to view the articles in the Microsoft Knowledge Base:

301986 List of the Knowledge Base articles that discuss database-related topics in FrontPage 2000


295192 What are Active Server Pages?


297943 Getting started with Active Server Pages


For more information about how to publish a Expression Web Web site, click Microsoft Expression Web Help on the Help menu, type publish in the Office Assistant or in the Answer Wizard, and then click Search to view the topics that are returned.

Keywords: kbhowto kbexpertiseinter KB928702