spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / javascript / column115


JScript .NET, Part IX: Code Behind

Sr Instructional Designer D2L-Moodle,Clearance
WSI Nationwide, Inc.
US-NJ-Fort Monmouth

Justtechjobs.com Post A Job | Post A Resume
Developer News
News Flash: Adobe Has iPhone Workaround
Adobe's Flash 10.1 Goes Mobile (Minus iPhone)
A Salute to Visionary CEOs


The IsPrime Consumer's Code Behind

Let's take the IsPrime Web service example now. We showed you in Column 114 how to consume this Web service from an ASP.NET page. Let's now 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 previous 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:


Next: How to write the IsPrime consumer's ASP.NET page

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


Produced by Yehuda Shiran and Tomer Shiran
All Rights Reserved. Legal Notices.
Created: July 29, 2002
Revised: July 29, 2002

URL: http://www.webreference.com/js/column115/8.html