ASP
  Home arrow ASP arrow Page 4 - Remote Scripting With JavaScript and ASP
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Dedicated Servers  
Actuate Whitepapers 
VeriSign Whitepapers 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP

Remote Scripting With JavaScript and ASP
By: Annette Tennison
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 26
    2002-12-14

    Table of Contents:
  • Remote Scripting With JavaScript and ASP
  • What is remote scripting?
  • Testing remote scripting
  • Enabling remote scripting on the server side
  • Another remote scripting example
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
    Iron Speed
     
    ADVERTISEMENT

    Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!

    Remote Scripting With JavaScript and ASP - Enabling remote scripting on the server side


    (Page 4 of 6 )

    Our client_test.html page includes JavaScript that is executed when a button is clicked on. This JavaScript contains a call to RSGetASPObject, which takes rev.asp as its first parameter.

    Create a new file called rev.asp and add the code shown below to rev.asp as we go. In order for rev.asp to participate in remote scripting, it must include the server version of rs.htm, which is rs.asp. Rs.asp includes a method called RSDispatch, which must be called immediately after rs.asp is included to initialise remote scripting:

    <!--#INCLUDE FILE="_ScriptLibrary/RS.ASP"-->

    <% RSDispatch %>


    Next we create a block of server side JavaScript code, like this:

    <script language="JavaScript" runat="server">



    var public_description = new MainMethod();

    function MainMethod()

    {

    this.revStr = Function('strString','return reverse(strString)');

    }

    </script>


    The code above creates a new object called public_description, which is an instance of a function called MainMethod. MainMethod is a constructor that contains a list of functions and how they should be mapped so that remote scripting can be used to call them. Note that the MainMethod function can be called anything you like.

    Before we continue, add the following block of VBScript at the end of rev.asp:

    <script language="VBScript" runat="server">

    function reverse(strString)

    reverse = strReverse(strString)

    end function

    </script>


    If you now take a look at the code inside of MainMethod, then you will see that it creates a new method called revStr, which maps to our VBScript reverse function:

    this.revStr = Function('strString','return reverse(strString)');

    Whenever a client calls the revStr method, remote scripting will automatically call our VBScript function reverse. The Function() method is used to define the revStr method. Its first argument is the parameter(s) that the function we're mapping to accepts. Our VBScript reverse function accepts one parameter, and we specify it using 'strString'. Next we have the function signature, which specifies the return keyword as well as the function name we're mapping and its parameters.

    Jumping back to our client_test.html, we have this code:

    function reverseString()

    {

    var strTest = prompt("Enter String To Reverse:");

    var objRS = RSGetASPObject("rev.asp");

    var objResult = objRS.revStr(strTest);



    alert(objResult.return_value);

    }


    As you can see, it uses RSGetASPObject to create a new object containing all of the functions that we've defined in rev.asp. Because we've mapped our VBScript function reverse as revStr, we call objRS.revStr with one parameter, which is the string that it should reverse and return.

    A call to any method of an object created from a call to RSGetASPObject returns an object itself. This object exposes several functions and variables, most notably return_value, which is the value returned from the call to the specific function (which in our case is revStr). In our client_test.html page, we use JavaScript's alert function to display the returned value in a message box.

    Here's the entire code for rev.asp:

    <!--#INCLUDE FILE="_ScriptLibrary/RS.ASP"-->

    <% RSDispatch %>

    <script language="JavaScript" runat="server">



    var public_description = new MainMethod();

    function MainMethod()

    {

    this.revStr = Function('strString','return reverse(strString)');

    }

    </script>

    <script language="VBScript" runat="server">

    function reverse(strString)

    reverse = strReverse(strString)

    end function

    </script>


    When I ran client_test.html in my web browser and entered "the sky is blue" into the popup window, it looked like this:

    Running client_test.html in IE

    Just to prove that remote scripting also works in Netscape, here's a screenshot from Netscape 4.74:

    Running client_test.html in Netscape

    Hopefully you've now got our first sample up and running. Let's build on what we've learnt so far and add some database functionality to the mix.

    More ASP Articles
    More By Annette Tennison


     

    ASP ARTICLES

    - Central Scoreboard with Flash and ASP
    - Calorie Counter Using WAP and ASP
    - Creating PGP-Encrypted E-Mails Using ASP
    - Be My Guest in ASP
    - Session Replacement in ASP
    - Securing ASP Data Access Credentials Using t...
    - The Not So Ordinary Address Book
    - Adding and Displaying Data Easily via ASP an...
    - Sending Email From a Form in ASP
    - Adding Member Services in ASP
    - Removing Unconfirmed Members
    - Trapping HTTP 500.100 - Internal Server Error
    - So Many Rows, So Little Time! - Case Study
    - XDO: An XML Engine Class for Classic ASP
    - Credit Card Fraud Prevention Using ASP and C...


    Iron Speed





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway