JScript .NET, Part VII: Consuming add from ASP.NET: Writing ASP.NET Controls - Doc JavaScript
JScript .NET, Part VII: Consuming add from ASP.NET
Writing ASP.NET Controls
An ASP.NET page is similar to an HTML page. It includes tags and event handlers. The tags' syntax is similar to that of HTML tags. You write event handlers in JScript .NET. To call the add
Web service, we use only two ASP.NET tags: ASP:BUTTON
and ASP:TEXTBOX
. All of ASP.NET's tag parameters are specified within the opening brackets, so you can end them with a "/
" inside the opening brackets, or with a "/
" concatenated with the tag name, in separate closing brackets. The following two formats are valid:
<ASP:TEXTBOX ...... /> <ASP:TEXTBOX ........></ASP:TEXTBOX>
ASP.NET pages are saved with the extension .aspx
. Our ASP.NET page that consumes the add
Web service is simpleCalcConsumer.aspx
. Here is the BODY
section of the ASP.NET page:
<BODY STYLE="font-size:12; font-family:arial,verdana,sans-serif;"> <FORM METHOD="post" 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>
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
. Since this form runs on the server, it is called the ASP.NET Web form, as opposed to the ASP.NET Windows form, used in Windows-based applications.
The Web form above includes three ASP:TEXTBOX
tags. Here is the first one:
<ASP:TEXTBOX RUNAT="server" SIZE="4" ID="first" STYLE="text-align:'right'"/>
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.
Next: How to write JScript .NET for ASP.NET
Produced by Yehuda Shiran and Tomer Shiran
All Rights Reserved. Legal Notices.
Created: June 30, 2002
Revised: June 30, 2002
URL: https://www.webreference.com/js/column113/6.html