Tips and Tricks using Remote Scripting by Salim N.

Contributed by
Rating: 2 stars2 stars2 stars2 stars2 stars / 4
August 29, 2000
Rate this Article:
MEH MEH++


SEARCH ASP FREE
TOOLS YOU CAN USE

advertisement

Okay this week i'm going to be covering one of the least used and arguably most useful asp trick that shipped with visual interdev.
RemoteScripting is one of those annoying things that get installed by visual interdev in it's _ScriptLibrary. personally i hate code that gets written for me without knowing what the code actually does so i always delete those underscore folders that interdev creates.today i'm going to tell you not to delete this folder just yet, saving the remote scripting content and this sample will show why this will provide you a very nifty trick.

Historically speaking remotescripting has been around for two years so it's not a new technology and in the future the introduction of SOAP (Simple Object Access Protocol) will phase this technology out. But for now it can be very very handy.
in my opinion the main reason why remotescripting has never been widely used by ASP programmer is because of the fact that in it's early implementation only server side JScript could be used and heaps of people implement ASP in VBScript so it never experienced full exposure (among other reasons). okay with this in place i'll continue...

Ever wanted to validate a primary key without actually posting a form?
Ever wished that you can call a function on the server from your client script without  submitting?

if you ever seeked to achieve the above and always came to the conclusion that it's just not possible in ASP then RemoteScripting is your savor, yes RemoteScripting is exactly what it's name implies. Remotescripting is a method to communicate with remote script over HTTP.

in this article i'm going to be showing an example of calling a function in an ASP page from a client-side javascript on a HTML page. The sample will show an example of a simple function call with just a boolean return, it will also show a more advance method of calling a function on the server and passing it parameters.
Now is a good time to state this, RemoteScripting is browser independent (yes Netscape) and with VBScript 5.X it's server class can be implemented with VBScript.

The Sample

#1

On the server in a page called remote.asp i have the following function, this file will be showed later on.

function SimpleFunction(){
return true;
}

Now to demonstrate the remote in remotescripting, clicking the below button will trigger this function from this page without posting

The code

objTest = RSExecute("remote.asp","SimpleFunction") 
alert(objTest.return_value);

 

 

above is the client side javascript code that was written to call the remote function on the server, first of all Remotescripting must
be enabled this is done by including the following code into the head of the calling page.


 <scriptlanguage="Javascript"src= "./_ScriptLibrary/rs.htm">
</script>
<scriptlanguage="Javascript">
RSEnableRemoteScripting("./_ScriptLibrary");</script>

once enabled using the RSExecute function, any remote scripting class in a asp page can have it's methods called and the result returned. The remote class can be on your server or another server providing you this service.

#2
Type text into the textbox belox and click the "Call Remote Function"

The Code

objTest = RSExecute("remote.asp","ParamFunction",document.frmRemote.txtParam.value) 
alert(objTest.return_value);


The second function is slightly more advance it takes parameters enter in the text box and passes them to the ParamFunction on the server. Now the function on the server can be anything you want them to be they could validate a value etc...
so you have seen what is on the client, here's the content on the server.

The Server Class

 

<%@ LANGUAGE=JScript%>
<% 
//the remote class
function clsRemoting()
{
this.SimpleFunction = _SimpleFunction;
this.ParamFunction = _ParamFunction; 
} 
//the is the function that getting called
function _SimpleFunction(){
return true;
}
function _ParamFunction(strvalue){
return ("Hi from " + Request.ServerVariables("SERVER_NAME") + 
" this is the paramter passed " + strvalue);
}
var public_description = new clsRemoting();
// Call RSDispatch to use the public_description object 
//and make its methods available for Remote Scripting Calls
RSDispatch(); %>
    

 

blog comments powered by Disqus
ASP CODE ARTICLES

- ASP Forms
- ASP: The Beginning
- Getting Remote Files With ASP Continued
- Inbox and Outbox Manipulation in ASP
- Relational DropDownList Using VB.NET
- Ad Tracking URL Hits
- Use ViewState to display one record per page...
- Send Email using ASP.NET formatted in HTML
- ASP File Explorer
- ASP/XML Interview questions by Srivatsan Sri...
- Pressing RETURN won't submit the form
- This shows how you get the TEXT of a combo r...
- Group Data by Adrian Forbes
- Multiple checkbox select sample
- Multiple checkbox select with all values sam...

ASP Web Hosting ASP.Net Web Hosting Windows Web Hosting
 
 
 

ASP Free Forums 
 RSS  Tutorials RSS
 RSS  Forums RSS
 RSS  All Feeds
Site Map 
Request Media Kit
Write For Us Get Paid 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Privacy Policy 
Support 


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 5 - Follow our Sitemap
Most Popular Topics
All ASP.Net Tutorials