spacer
Yehuda Shiran August 6, 2002
Writing IsPrime's Event Handler
Tips: August 2002

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
News Flash: Adobe Has iPhone Workaround
Adobe's Flash 10.1 Goes Mobile (Minus iPhone)
A Salute to Visionary CEOs

The top portion of an ASP.NET page includes two types of directions. First, the scripting language is specified:

  <%@ Page LANGUAGE="JScript" %>
Secondly, you need to specify the namespaces you want to import. For example:

  <%@ import namespace="primeProxy" %>
where the namespace is set during the wsdl command.

ASP.NET pages may include JScript .NET code, much the same as an HTML page may include JavaScript code. The JScript .NET section follows these directives. It has one function, Submit_Click(), which is the event handler of the ASP:BUTTON control:

  public function Submit_Click(sender:Object, E:EventArgs) : void {
    var result : String;
    var webService : PrimeNumbers;
    webService = new PrimeNumbers();
  
    result = webService.IsPrime(int.Parse(first.Text));
    resultControl.Text = (result == 0 ? " is not a prime number": 
                                        "   is a prime number") ;
  }
We define an object webService of the PrimeNumbers class. The class PrimeNumbers is the Web service class, and is stored in the primeProxy namespace of the .NET framework. We call the Web service by calling the IsPrime() method of the object webService. We pass the input integer number to IsPrime(). The value of the ASP:TEXTBOX control is its Text field. Therefore, the input number is first.Text. Since it is a textual entry, we need to parse it as an integer value by sending it to the method int.Parse().

The answer sent back by the Web service is stored in result. Finally, the value of result is written in the ASP:LABEL's Text entry of resultControl.

To learn more about JScript .NET and ASP.NET, go to Column 114, JScript .NET, Part VIII: Consuming IsPrime from ASP.NET.


People who read this tip also read these tips:

Look for similar tips by subject:

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

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

webref The latest from WebReference.com Browse >
Building a Banking Application Home Page with OOP · Mixing Scripting Languages · Review: phpFox, a Social Networking CMS with all the Bells and Whistles
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Enterprise 2.0: Social Networking in the Cloud · BroadSoft Marketplace Hastens Pace of Telephony Innovation · Review: HTC Hero for Sprint