August 6, 2002 - Writing IsPrime's Event Handler
August 6, 2002 Writing IsPrime's Event Handler Tips: August 2002
Yehuda Shiran, Ph.D.
|
<%@ 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.