
|
Expose functions in ASP remote scripting
As we've mentioned in other tips, Remote Scripting offers a great way to communicate directly between a client Web page and the server. IIS's remote scripting option lets you create server functions in either JavaScript or VBScript (assuming you have VBScript 5.0+). To do so, in the RS.asp page you declare a JavaScript constructor function then provide a laundry list of the functions you want to expose to the client page, like so:
<script language="JavaScript" runat="server" > var public_description = new srvMethods(); function srvMethods(){ this.myMethod1 = jsFunctionOne; this.myMethod2 = Function("someArg", "return vbFunctionTwo(someArg)");} </script>
Notice the pecular syntax of the myMethod2 function. This syntax is required when you want to use a VBScript function in JavaScript. The Function() function requires two parameters. First, you enter the VBScript function's arguments in a comma-delimited string. For example, if vbFunctionTwo contained two arguments, this string might appear as
"someArg1, someArg2"
In addition to this list of arguments, the second parameter in Function() requires the full syntax shown above-the function declaration, including it's arguments. Declared in this fashion, our public_description object now exposes two methods. The first, myMethod1, is written in JavaScript; the second, myMethod2, is written in VBScript. The JavaScript function might look like this:
<script language="JavaScript" runat="server" > function jsFunctionOne(someArg){ return "Hello, " + someArg;} </script>
and the VBScript version
<script language="VBScript" runat="server" > Function vbFunctionTwo(someArg) vbFunctionTwo = "Hello, " & someArg End Function </script> |
||||
| Search RD Techbase | ||||
![]()