WHIDBEY client callback mechanism (1)

zhaozj2021-02-16  44

Simplified WHIDBEY to client callback

There are many reasons to look forward to the next version of VS.NET: Whidbey, one of them is to add a lot of support for client scripts. Contains new properties and a ClientScriptManager class to manage client scripts. However, perhaps the most popular is whidbey supports the client script that calls the callback remote server is using.

Figure 1. The process of callback: When it is processed by both the server and the client, you can control the process of callback

Submitting a page by refreshing or flying to implementing a data query is a very common technology. When using the ASP, the developer uses the script to control the data submitted by the client, but this usually makes the ASP code difficult to maintain. Like most of the Web Applications, submit data to the server to submit a data in the form of a complete request - response cycle, the server generates a full new page to respond request, then the browser generates a new page to replace existing page. Page-redrawing enables the user to get the number of servers to respond slowly. One way to mitigate the interface problem of this problem is to use the remote scripting, this remote script uses the DHTML combination of Java Applets to dynamically generate requests to the server on the existing page.

In addition, developers can also use (IE requests only) client scripts and XMLHTTP to send requests to server background data.

However, it is difficult to implement the implementation of these two methods, which requires very careful and effort, especially compilation.

Developers are looking forward to getting some changes in the initial ASP.NET Release version, they get some, such as server controls, viewstate, auto-postback, and event-based ASP.NET programming models solve many problems. Especially SmartNavigation (only in IE applications). But in order to achieve cross-platform applications, developers continue to rely on remote scripts. This problem has been fundamentally changing in ASP.NET V2.0 (Whidbey).

Whidbey support for customer callback

In the WhidBey version, the client can call the server method to submit the data and get the result without submitting the form. These calls you write very little special code, use the XML HTTP of the background to implement the server request.

Figure 1 shows the application logic flow.

You have written a client function that issues a request (step 2) and defines a server event (step 1 c) to process this request. CallbackManager is like a transfer station that handles steps 3 to step 6. Includes issues and data from the client to the server to return from the server to the client.

Another client function (step 7) handling the return information of the server. You have written two client functions to use to want the server to issue a request and handle the return information of the server.

Implementation Query assumes that you need to create a page to implement query data from 3 database tables: Region, Country, And City. (See Figure 2)

This is a typical example of a "defendent list" problem. When a user selects a region, the program should be used to bind Country List in countries in this area. Similarly, when a user selects a country, City List should include a city corresponding to the country selected. (See Figure 2)

Of course, you can use normal postback technology to implement this writing, but you must endure the performance cost of redrawing the entire page each time a request is requested. However, because you can maintain all page layout code, you can provide a better, faster way to implement this function, this is the use of remote callbacks, only sending the corresponding identity each time and is only those Corresponding data.

Download this article code, the code includes the Callback.sql database script for establishing those data this document. You can use the SQL Server or MSDE database. First run the database script, (you can change as needed to use other databases). Then start Visual Studio.Net Whidbey creation example.

Create an engineering, select the template type "ASP.NET Web Site" (see Figure 3). This creates a new page DEFAULT.ASPX. If you want to rename it.

Template Selection: Select the ASP.NET website item in the template selection conversation in Visual Studio

In addition to the DEFAULT.ASPX page, DropDown Control is shown in Figure 4.

You can view and copy all from this article download code with the code included in .

To achieve remote callback, ICALLBACKEVENTHANDLER interface must be implemented. Add the following code to the page.

<% @ IMPLEMENTS Interface =

"System.web.ui.ICALLBACKEVENTHANDLER"%>

THIS Interface Has A Single Public Event Definition That You Must Implement:

Public String RaiseCallBackevent (

String eventargument) {

// Server Side Handling Here ...

}

Remote callback causes the client to generate raiseCallBackevent. So you should process and return to the corresponding information based on the clientGument. You can see this method parameter from the method signature as a string and return a string.

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

New Post(0)