July 31, 2002 - The onclick Event Handler | 2 | WebReference

July 31, 2002 - The onclick Event Handler | 2

Yehuda Shiran July 31, 2002
The onclick Event Handler
Tips: July 2002

Yehuda Shiran, Ph.D.
Doc JavaScript

When consuming the add Web service, we call the JScript .NET function, Submit_Click(). It is the event handler of the ASP:BUTTON control. Here is the code:

  public function Submit_Click(sender:Object, E:EventArgs) : void {
    var result : String;
    var webService : simpleCalc;
    webService = new simpleCalc();
    result = webService.add(int.Parse(first.Text), int.Parse(second.Text)).ToString();
    resultControl.Text = result;
We define an object webService of the simpleCalc class. The class simpleCalc is the Web service class, and is stored in the simpleCalc namespace of the .NET framework. We call the Web service by calling the add() method of the object webService. We pass the two input integer numbers to add(). The value of the ASP:TEXTBOX control is its Text field. Therefore, the two input numbers are first.Text and second.Text. Since they are textual entries, we need to parse them as integer values by sending them 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:TEXTBOX entry of resultControl.

To learn more about JScript .NET and ASP.NET, go to Column 113, JScript .NET, Part VII: Consuming add from ASP.NET.