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

JScript .NET, Part VIII: Consuming IsPrime from ASP.NET: JScripting for ASP.NET - Doc JavaScript


JScript .NET, Part VIII: Consuming IsPrime from ASP.NET

JScripting for ASP.NET

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" %>

Remember primeProxy from Page 2? This is the namespace you specified 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 the directives. It has one function, Submit_Click(). It 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 (see Page 2). 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.


Next: How to consume the IsPrime Web service


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/5.html