|
|
|
|
|||||||||||||||
Article Index . Remote Scripting in .NET - Part I
Part I covers the comparison of Remote Scripting with Web Services, how to enable Remote Scripting to work in .NET and demonstrates a new Remote Scripting "test bed" that is available. IntroductionRemote Scripting is a technology for ASP used to call server side code from a client browser without incurring the penalty of a round trip (GET or POST) to the server. Typically this is used to look up details by an identifier (for example, a product name by UPC or a book author by ISBN) while a user is completing a form. The .NET framework does not include built-in support for Remote Scripting on the server side but rather promotes Web Services as the preferred alternative. While Web Services have their advantages, they are not perfect for all purposes and Remote Scripting still has a place in our .NET toolbox. For more information on Remote Scripting in ASP, see the MSDN Documentation. Remote Scripting in .NET - Pros
Remote Scripting in .NET - Cons
Follow these 7 steps to get Remote Scripting working and tested in your ASP.NET application. 1)Download the Thycotic.Web.RemoteScripting assembly which provides the replacement server side plumbing (source code is also available under the LGPL) from Thycotic Software Ltd. 2)
Add a reference to this assembly to your ASP.NET project.
![]() 3) Add a Remote Scripting client. Choose one of the following:
4)
Create a new Web Form that will contain the server-side methods you wish to call from the browser.
Call it for example, In your code behind page (MyServerSidePage.aspx.cs)
using System;
using Thycotic.Web.RemoteScripting;
namespace TestRemoteScripting1
{
public class MyServerSidePage
: Thycotic.Web.RemoteScripting.RSPage
{
[RemoteScriptingMethod(Description="Converts text to upper case.")]
public virtual string ToUpperCase(string s)
{
return s.ToUpper();
}
[RemoteScriptingMethod]
public virtual DateTime GetServerTime()
{
return DateTime.Now;
}
}
}
In your front page (MyServerSidePage.aspx) <%@ Page language="c#" Codebehind="MyServerSidePage.aspx.cs" AutoEventWireup="false" Inherits="TestRemoteScripting1.MyServerSidePage" %> 5)
Try out your server side page by viewing it in your browser. You will see a new "test bed"
for Remote Scripting (provided by Thycotic.Web.RemoteScripting assembly) which allows you to test
your server side code.
![]() 6)
Create a Web Form with client side script to call your Remote Scripting method.
<%@ Page language="c#" Codebehind="SimpleClientPage.aspx.cs"
AutoEventWireup="false" Inherits="SampleRemoteScripting.SimpleClientPage" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<html>
<head>
<title>SimpleClientPage.aspx</title>
<!-- Microsoft Remote Scripting client -->
<SCRIPT LANGUAGE="JAVASCRIPT" SRC="/TestRemoteScripting1/_ScriptLibrary/rs.htm">
</SCRIPT>
<SCRIPT LANGUAGE="JAVASCRIPT">
RSEnableRemoteScripting("/TestRemoteScripting1/_ScriptLibrary");
</SCRIPT>
<!-- Uncomment to use the Thycotic msrsclient.js client -->
<!-- <SCRIPT LANGUAGE="JAVASCRIPT" SRC="msrsclient.js"></SCRIPT> -->
<SCRIPT language="javascript">
var aspObject;
var serverURL = "MyServerSidePage.aspx";
function ToUpperCase() {
var result = RSExecute(serverURL,"ToUpperCase",document.myForm.stringInput.value);
if (result.return_value) {
document.myForm.stringOutput.value = result.return_value;
}
}
</SCRIPT>
</head>
<body MS_POSITIONING="FlowLayout">
<form id="myForm" name="myForm">
Very simple client page.<br/><br/>
Single text value:
<input type="text" name="stringInput" id="stringInput" value="hello">
<a href="javascript:ToUpperCase()">ToUpperCase</a><br/>
Result: <input type="text" name="stringOutput" id="stringOutput" value="">
</form>
</body>
</html>
7)
View the Web Form to try it for yourself.
![]() Functionality Contribute Conclusion *WORKING DEMO* of Remote Scripting in .NET Related Downloads Related Links Copyright © 2002 Thycotic Software Ltd. | |||||||||||||||||
| Copyright © 2000-2003 ASPAlliance.com Page Rendered at
11/21/2009 6:12:53 PM |
|||||||||||||||||