Microsoft KB Archive/928702

= How to use Active Server Pages to complete mathematical calculations on a form before you send data to a database in Expression Web =

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:

 New Page 1

    

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:  In Expression Web, click the Send.asp file. Click the Code tab on the bottom of the page to switch to HTML view.</li>  Copy the following code, and then paste it above the initial &quot; &quot; tag at the top of the page: <% dim n, c, t n = request(&quot;number&quot;) c = request(&quot;cost&quot;) t = c*n %> </li> Click the Design tab on the bottom of the page to switch to normal view.</li> In the Toolbox section, drag a Form control to the page.</li> Click the Code tab on the bottom of the page to switch to HTML view.</li>  Copy the following code, and then paste it immediately after the &quot;<form method=&quot;POST&quot; action=&quot;--WEBBOT-SELF--&quot;>&quot; 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. </li> Click the Design tab on the bottom of the page to switch to normal view.</li> Right-click the form, and then click Form Properties.</li> In the Form Properties dialog box, click Advanced.</li> In the Advanced Form Properties dialog box, click Add.</li> In the Name/Value Pair dialog box, type cost in the Name box, and then type <%=c%> in the Value box.</li> Click OK.</li> In the Advanced Form Properties dialog box, click Add.</li> In the Name/Value Pair dialog box, type number in the Name box, and then type <%=n%> in the Value box.</li> Click OK.</li> In the Advanced Form Properties dialog box, click Add.</li> In the Name/Value Pair dialog box, type total in the Name box, and then type <%=t%> in the Value box.</li> <li>Click OK two times.</li> <li>In the Form Properties dialog box, click Send to database (Requires FrontPage Server Extensions), and then click Options.</li> <li>In the Options for Saving Results to Database dialog box, click Create Database, and then click OK in the confirmation dialog box that appears.</li> <li>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.</li> <li>Click OK two times.</li> <li>Save both pages.</li> <li>To publish the pages, click Publish Site on the File menu.</li> <li>In the Publish Destination dialog box, type the URL of the server, and then click OK.</li> <li>Test the pages, and then verify that the values and the total are inserted in the database.</li></ol>

<div class="references_section">