July 28, 2002 - Writing Web Forms | WebReference

July 28, 2002 - Writing Web Forms

Yehuda Shiran July 28, 2002
Writing Web Forms
Tips: July 2002

Yehuda Shiran, Ph.D.
Doc JavaScript

An ASP.NET form that runs on a Web server is called an ASP.NET Web form, as opposed to the ASP.NET Windows form, used in Windows-based applications. Here is a form that calls the add Web service:

  <FORM METHOD="post" RUNAT="server">
  <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" 
  <TR><TD></TD><TD><ASP:TEXTBOX ID="resultControl" RUNAT="server" 
    STYLE="text-align:'right'" SIZE="4"/></TD></TR>
All tags include the RUNAT="server" parameter, directing the browser to run it on the Web server. The first tag is FORM. Its only parameter is RUNAT="server". By default, the server always posts the form back to the same originating page, simpleCalcConsumer.aspx. The Web form above includes three ASP:TEXTBOX tags. Here is the first one:

  <ASP:TEXTBOX RUNAT="server" SIZE="4" ID="first" 
The parameters are straightforward. The ID parameter is used to reference the control from other places on the page such as event handlers. Notice we use the short-hand notation for closing tags. The first ASP:TEXTBOX tag's ID is first, the second is second, and the third is resultControl. The ASP:BUTTON tag is as follows:

  <ASP:BUTTON TEXT="Add" ID="doAdd" OnClick="Submit_Click" RUNAT="server"/>
The parameters are TEXT and ID. The TEXT parameter specifies the label of the button. We set it to "Add". Its ID is doAdd. In the event of a click, the function Submit_Click() is called.

To learn more about JScript .NET and ASP.NET, go to Column 113, JScript .NET, Part VII: Consuming add from ASP.NET.