Ashless refresh page in ASP.NET 2.0
"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. such as,
Lostinet
of
Rane
It 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:
Result: When the button is clicked, JS will call Script method CALLTOSERVER (), JS script is as follows:
function callToServer () {var param = document.getElementById ( "txtUsername") value;. var context = ""; <% = ClientScript%> <% = ClientScript%>} function handleResultFromServer (result, context) {document.getElementById ( "txtResult"). value = result;} HandleResultFromServer () method is responsible for writing the data sent from the server to TXTRESULT text box. Take a look at the code of the server:
public partial class Default_aspx: System.Web.UI.ICallbackEventHandler {private String ClientScript {get {return this.GetCallbackEventReference (this, "param", "handleResultFromServer", "context");}}