ASP.NET 2.0, no refresh page new realm!

xiaoxiao2021-03-06  51

"No refresh page" is just an inactive effect description (in fact, there are other methods to achieve this effect), more precise statement is: use JavaScript to call a method of the server side with JavaScript and then process the returned data. . Implementing its most standard method is of course XMLHTTP. However, programmers are lazy guys, everyone wants to have more convenient methods, or better packaging. For example, Lostinet's Rane is a good packaging for XMLHTTP. Finally, in ASP.NET 2.0, we can easily do this. Server-side Any control of the System.Web.ui.ICALLBACKEVENTHANDLER interface can be processed from the request and data passed from the JS script on the page through the RaiseCallBackevent () method, and then transfer the result back to the page. The bottom layer of this ability is still XMLHTTP. Here is a simple presentation: On the page, we put two text boxes and a button: When the button is clicked, the JS script method CALLTOSERVER (), the JS script is as follows: function calltoServer () {var param = document.getlementByid ("txtusername"). Value ; var context = ""; <% = ClientScript%> <% = ClientScript%>} function handleResultFromServer (result, context) {document.getElementById ( "txtResult") value = result;.} handleResultFromServer () method is responsible from The data transferred by the server is written to the TXTRESULT text box. Look server code: public partial class Default_aspx: System.Web.UI.ICallbackEventHandler {private String ClientScript {get {return this.GetCallbackEventReference (this, "param", "handleResultFromServer", "context");}}

转载请注明原文地址:https://www.9cbs.com/read-113292.html

New Post(0)