JScript .NET, Part IX: Code Behind: Writing the add Consumer's ASP.NET Page - Doc JavaScript | WebReference

JScript .NET, Part IX: Code Behind: Writing the add Consumer's ASP.NET Page - Doc JavaScript

JScript .NET, Part IX: Code Behind

Writing the add Consumer's ASP.NET Page

The ASP.NET page is much shorter when you use Code Behind. Here is simpleCalcConsumerForm.aspx:

<%@ Page LANGUAGE="JScript"
  INHERITS="ASPPlus.codeBehind" %>
  <TITLE>simpleCalc XML Web Service Test</TITLE>
<BODY STYLE="font-size:12;
  <FORM RUNAT="server">
    <TABLE BORDER="0">
      <TR><TD>Enter First Number:</TD>
      <TD><ASP:TEXTBOX RUNAT="server" SIZE="4" ID="first"'
      <TR><TD>Enter Second Number:</TD>
      <TD><ASP:TEXTBOX RUNAT="server" SIZE="4" ID="second"
      <TR><TD align="right">
      <ASP:BUTTON TEXT="Add" ID="doAdd" OnClick="Submit_Click"
      <ASP:TEXTBOX ID="resultControl" RUNAT="server"
         STYLE="text-align:'right'" SIZE="4"/></TD></TR>

The top line is a directive line. It instructs the Web server about the LANGUAGE, SRC, and INHERITS. The SRC specifies the Code Behind file name. The Web server reads the INHERITS attribute and searches the bin directory (underneath the current working directory) for a dll file that includes the definition of ASPPlus.codeBehind. If the Web server does not find this class, it will generate the dll file from the code specified by the SRC attribute.

As we have explained in Column 113, there are three ASP:TextBox controls and one ASP:Button control. The TextBox controls are for entering the two numbers and displaying the result. The Button is for triggering the addition between these two numbers. You define the event handler of this button by the OnClick attribute, OnClick="Submit_Click". The Submit_Click() function is defined in the Code Behind. It is responsible for calling the add Web service with the input numbers, and displaying the result in the bottom ASP:TextBox control. For each TextBox we specified its length (4), and its text-alignment (right).

The communication between the ASP.NET page and the Code Behind page is done via the element IDs. The Code Behind reads the values of the input numbers from their Text property: first.Text and second.Text. The result TextBox is disabled by setting resultControl.Enabled to false. It is set to the result of the addition by setting its Text property, resultControl.Text, to the addition result.

Next: How to write the IsPrime consumer's Code Behind

Produced by Yehuda Shiran and Tomer Shiran
All Rights Reserved. Legal Notices.
Created: July 29, 2002
Revised: July 29, 2002

URL: http://www.webreference.com/js/column115/7.html