JScript .NET, Part VIII: Consuming IsPrime from ASP.NET: Writing ASP.NET Controls - Doc JavaScript | WebReference

JScript .NET, Part VIII: Consuming IsPrime from ASP.NET: Writing ASP.NET Controls - Doc JavaScript


JScript .NET, Part VIII: Consuming IsPrime 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 IsPrime 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 IsPrime Web service is checkIsPrime.aspx. Here is the BODY section of the ASP.NET page:


<BODY STYLE="font-size:12;
  font-family:arial,verdana,sans-serif;">
  <FORM RUNAT="server">
    <TABLE BORDER="0">
      <TR>
       <TD ALIGN="middle"><ASP:TEXTBOX ID="first"
        RUNAT="server" SIZE="4" STYLE="text-align:'right'"/>
        </TD>
       <TD ALIGN="middle"><ASP:LABEL ID="resultControl"
        RUNAT="server"/></TD>
	  </TR>
	  <TR>
	    <TD><ASP:BUTTON TEXT="Is Prime?" ID="isprime"
		  OnClick="Submit_Click" RUNAT="server"/></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, isPrimeConsumer.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 a single ASP:TEXTBOX tag:

<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 ASP:TEXTBOX tag's ID is first. The ASP:LABEL tag is as follows:


<TD ALIGN="middle">
<ASP:LABEL ID="resultControl" RUNAT="server"/>
</TD>

The button is implemented with the ASP:BUTTON tag:


<ASP:BUTTON TEXT="Is Prime?"
  ID="isprime" OnClick="Submit_Click" RUNAT="server"/>

The parameters are TEXT and ID. The TEXT parameter specifies the label of the button. We set it to "Is Prime?". Its ID is isprime. 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: July 15, 2002
Revised: July 15, 2002

URL: http://www.webreference.com/js/column114/4.html