spacer

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

home / experts / javascript / column114


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

Sr. Web Developer
mediabistro.com
US-NY-New York

Justtechjobs.com Post A Job | Post A Resume
Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?


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

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

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

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business


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