One Script Callback you implemented
Yesterday, the online friend recommended me to read an article "Remote scripting in .Net", the author of this article uses Microsoft Remote Scripting technology, some encapsulation in the server side, which is convenient for the page in ASP.NET. Call directly to call the server-side method. It is said that I used to Microsoft Remote scripting or quite strange. The principle of MRS is to use a built-in Java Applet, through some high-level packages, so that the page can directly call the server on the server on the server. Interested friends can take a look at the documents on MSDN, which is convenient, especially the package of the package of the authors of the article. Net components. However, my individual is not very cold, especially in the machine in my family, is not available on the machine that does not install JRE, but I don't use it. My favorite is the Script Callback in ASP.NET 2.0. The same implementation, simple, clear, so I think, since it is also using XMLHTTP to be implemented, it is better to use XMLHTTP to implement it under ASP.NET 1.1. I spent a meal, I'm doing. Most of them are implemented in the implementation of the ASP.NET 2.0, but some places can still be exactly the same, because I can't write directly to the Page class or more in the process of implementing the control of the ICALLBACKEVENTHANDLER interface. You need to create a ScriptCallbackManager control in the page. Server-end procedures: Add a ScriptCallbackManager control in the page, indicating the control of the ICallBackeventHandler interface, and execute the script function name after the call is completed. public class WebForm1: System.Web.UI.Page, ICallbackEventHandler {private void Page_Load (object sender, System.EventArgs e) {this.Controls.Add (new ScriptCallbackManager (this, "handleResultFromServer"));}
PUBLIC STRING RAISECALLBACKEVENT (STRING EVENTARGUMENT) {Return "You Sent" Eventargument "!";} Page: 1 To pass the variable to the server side, the second parameter specifies the context of the request; 2. Write a function that automatically executes after the call is completed, the name of this function needs to be specified in the constructor of the server-side ScriptCallbackManager control. The name is the same. Function callback () {var param = document.all.txtRequest.Value; var context = ""; scriptcallback (param, context);}
Function HandleResultFromServer (Result);} The system built-in Script Function ScriptCallback () is called in the callback () method. This function will automatically call the server method and pass the value of the first parameter. The server-side RaiseCallBackeVent () method parameters. HandleResultFromServer is a function that is automatically executed after the call is completed. Interested friends can download the project source code for this Script Callback implementation here. Published in Monday, August 02, 2004 11:39 PM
Transfer from: Kaneboy's CodingLife Blog