Ashless refresh page in ASP.NET 2.0

zhaozj2021-02-16  79

[

Original Source] Author:

Kaneboy

"Non-refresh page" is just an inactive effect description (in fact there are other methods to achieve this effect), more precise statements are:

Use the 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

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 demonstration:

On the page, we put two text boxes and a button:

Result:

When the button is clicked, the JS script method CALLTOSERVER (), the 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;

The HandleResultFromServer () method is responsible for writing the data sent from the server to the 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");}}

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

New Post(0)