.Net Remote Script Request
Have you ever wanted an easy way to call a server side method from javascript? If so this class may be just what you need.
I have created a simple and easy to use method for accomplishing this task. All you have to do is have your webform inherit from the remote script page, make your call using a simple javascript object (will be included automatically), and when you execute the request in javascript the OnRemoteScriptRequest event will be raised in your server side code, you then process the request and write the result out on the response stream. The result will be returned by the javascripts execute method.
This .Net class library uses a combination of C# code and javascript to accomplish the task in an easy to use manner. The call uses Microsoft.XMLHTTP, Msxml2.XMLHTTP or XMLHttpRequest objects (depending on the browser) to do the underlying call back to the server. Because of this it will work in all recent IE and Mozilla based (Firefox, Netscape, Mozilla, etc.) browsers.
Try It Here!
Here it is step by step
- Include a reference to RemoteScript.dll
- Have your webform inherit from the remote script page:
public class WebForm1 : RemoteScript.Pages.RemoteScriptPage - Add the event handler in the InitializeComponent method
this.OnRemoteScriptRequest += new RemoteScript.Pages.RemoteScriptEventHandler(RemoteScriptTest_OnRemoteScriptRequest); -
Add the event handler method
private void RemoteScriptTest_OnRemoteScriptRequest(object sender, ... -
After you add your code to the event handler you will be able to call it from javascript using the RemoteScriptRequest javascript object, Example:
objRS = new RemoteScriptRequest();
strReturnValue = objRS.Execute();
Donload the source code and a sample webform here
You can view the documentation here: html - chm