spacer
Yehuda Shiran August 17, 2002
Consuming the IsPrime Web Service using Code Behind
Tips: August 2002

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
OpenOffice 3.2 Lands Amid Critical Changes
Red Hat, IBM Firmly in KVM Virtualization Camp
Red Hat Talks Up Open Source Cloud Plans

In Column 114 we showed you how to consume the IsPrime Web service from an ASP.NET page. Now, let's split the presentation from the business logic by putting the JScript .NET code in a separate Code Behind file. Here is the code:

  import System.Diagnostics;
  import System.Xml.Serialization;
  import System;
  import System.Web.Services.Protocols;
  import System.ComponentModel;
  import System.Web.Services;
  import primeProxy;

  package ASPPlus {
   
    class codeBehind extends System.Web.UI.Page {

      public var resultControl : System.Web.UI.WebControls.Label;
	  public var first : System.Web.UI.WebControls.TextBox;
	
      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 use the same namespace (ASPPlus) and class (codeBehind) as in other pages, so be sure to re-compile your Code Behind before displaying the ASP.NET page. We define two properties and one function. The property resultControl is the Label where we display the result of the IsPrime check. The property first is the TextBox where we read the input number from.

The function Submit_Click() is triggered by the button on the ASP.NET page and it calls the IsPrime Web service. It also sets the Text property of the resultControl Label.

Again, the communication between the ASP.NET page and the Code Behind is through the dll files in the bin directory. The ASP.NET page looks for the namespace ASPPlus, and for the class codeBehind inside it. Therefore, you need to compile the Code Behind into a dll file:

jsc /t:library /out:bin\codebehind.dll /r:bin\sampleproxy.dll 
  IsPrimeConsumerForm.aspx.js
Notice that we make sure the compiler finds the primeProxy namespace in the sampleProxy.dll file, by specifying the /r: switch. The following Command Control window shows the code listing as well as the compiler response:

To learn more about JScript .NET and ASP.NET, go to Column 115, JScript .NET, Part IX: Code Behind.


People who read this tip also read these tips:

Look for similar tips by subject:


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

webref The latest from WebReference.com Browse >
Search Engine Optimization: Selecting and Embedding Keywords · Are Google's Language Translation Web Services Ready for Prime Time? · Installing and Using Meeplace, the Business Review CMS
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Workers Say Telework Is More Productive, Bosses Not So Sure · Kingston Debuts Power-Saving Memory Upgrades · Social Networking is King: Facebook Edges Google