Version

Summing Two Controls at Design Time

Before You Begin:

WebCalcManager™ adds an extender property called CalcSettings to any control. The CalcSettings property allows for a control to participate in the calculation network. This allows calculations to be performed using almost any control as either the source or destination of a calculation, or possibly both.

This walk through takes the values of two text boxes and adds them together and places the resulting value in a label.

Follow These Steps:

  1. Start by placing two TextBox controls on a WebForm. These will be used as source values for the sum calculation.

  2. Add a Label to the WebForm. The Label will be used to display the formula result. A Label is used because the destination of a Formula should not be editable by the user.

  3. Add a Button to the WebForm. This button will be used to post back to the server and cause the CalcManager to recalculate.

  4. Place an UltraCalcManager component on the WebForm. You form should look something like the following.

WebCalcManager Summing Two Controls at Design Time 01.png
  1. Before any control can be used in a formula, the WebCalcManager needs to know which property of the control to use as the value of the Control. This is specified using the CalcSettings.PropertyName property.

Start with the first TextBox on the form (textBox1) and find the CalcSettings property. Expand this property and find the PropertyName property. Click the DropDown arrow to see a list of suggested properties to use. Note that any property of the control can be used; this list is just a suggestion of the most common properties. Choose "Text" from the list.

WebCalcManager Summing Two Controls at Design Time 02.png

Repeat this process for TextBox2 and Label1.

  1. Once the PropertyNames have been set, the controls will show up in the FormulaBuilder dialog. Go to the CalcSettings property of the Label and find the Formula property. Click the ellipsis to bring up the FormulaBuilder.

On the left-hand side of this dialog is the Operands list. The Operands list is a tree of objects which can be used in a formula. Expand the Controls node and you will see the Label and the two TextBoxes. Each entry will be followed by a ".Text" indicating that the Text property of that control will be used.

WebCalcManager Summing Two Controls at Design Time 03.png

Notice that the Label1 node is disabled. That is because it is the control for which the current Formula is being designed. Referencing itself would cause a circular reference, so the FormulaBuilder does not allow its node to be selected.

On the top right is the Formula window. This is where the formula you are building is shown. Under the Formula window is a row of useful buttons, like +, -, /, *, etc.

Under the row of buttons is the Formula Status window. This window will display the status of the Formula and indicate if there are any errors. Currently, it will say "No formula," indicating that there is no formula (because the Formula window is blank).

  1. Double-click on the TextBox1.Text node. A reference to this control appears in the formula window on the right. Note that it is properly formatted with square brackets and double slashes to indicate a reference like so: "[//TextBox1]".

WebCalcManager Summing Two Controls at Design Time 04.png

Notice that the Formula Status window on the bottom right has changed from "No Formula" to "Formula Compiled Successfully." A single reference is not very interesting, but it is a perfectly valid formula.

Now click the plus () button or press the plus () sign on the keyboard.

At this point, the formula status window changes again and displays something like: "Unexpected end of file, on line: 1 column: 15". This is because there’s a plus sign hanging at the end of the formula with nothing to add.

Double-click on the TextBox2.Text node in the Operands tree to complete the formula. Notice that the formula status shows "Formula Compiled Successfully" again.

WebCalcManager Summing Two Controls at Design Time 05.png
  1. Click OK to apply the formula. The FormulaBuilder will close and the Formula is copied into the Formula property of Label1’s CalcSettings.

  2. Now run the application.

WebCalcManager Summing Two Controls at Design Time 06.png
  1. Label1 will display 0. Change the Text of TextBox1 and TextBox2 to something numeric. Once there are valid numbers in each of the TextBox controls and the ReCalculate button is clicked, the Label will display the sum of the two numbers.

WebCalcManager Summing Two Controls at Design Time 07.png

What You Accomplished:

This walk through was designed to show you how simple it is to use the WebCalcManager to perform calculations with almost any editable control.