spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / javascript / column115


JScript .NET, Part IX: Code Behind

Technical Lead
Thomson Reuters (Markets) LLC
US-NY-New York

Justtechjobs.com Post A Job | Post A Resume
Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?


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"
  SRC="simpleCalcConsumerForm.aspx.js"
  INHERITS="ASPPlus.codeBehind" %>
<HTML>
<HEAD>
  <TITLE>simpleCalc XML Web Service Test</TITLE>
</HEAD>
<BODY STYLE="font-size:12;
  font-family:arial,verdana,sans-serif;">
  <FORM RUNAT="server">
    <TABLE BORDER="0">
      <TR><TD>Enter First Number:</TD>
      <TD><ASP:TEXTBOX RUNAT="server" SIZE="4" ID="first"'
        STYLE="text-align:'right'"/></TD></TR>
      <TR><TD>Enter Second Number:</TD>
      <TD><ASP:TEXTBOX RUNAT="server" SIZE="4" ID="second"
        STYLE="text-align:'right'"/></TD></TR>
      <TR><TD align="right">
      <ASP:BUTTON TEXT="Add" ID="doAdd" OnClick="Submit_Click"
        RUNAT="server"/></TD><TD><HR></TD></TR>
      <TR><TD></TD><TD>
      <ASP:TEXTBOX ID="resultControl" RUNAT="server"
         STYLE="text-align:'right'" SIZE="4"/></TD></TR>
    </TABLE>
  </FORM>
</BODY>
</HTML>

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

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business


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