Client callback mechanism in Whidbey (i)

Source: Internet
Author: User
Tags contains visual studio
Client Whidbey simplification of client callbacks

There are many reasons to expect the next version of Vs.net: Whidbey, one of which is to add a lot of support for client-side scripting. Contains new properties and a ClientScriptManager class to manage client script. Perhaps the most popular, however, is Whidbey support for callback client script that the remote server is using.















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









It is a common technique to implement a data query by refreshing or sending a postback to a page. When using ASP, developers use scripts to control the data submitted by the client, but this often makes the ASP code difficult to maintain. Like most Web applications, submitting data to a server in the form of a submit postback causes a complete request-response cycle, the server generates a completely new page to respond to the request, and the browser generates a new page to replace the existing page. Page Redraw (page-redrawing) makes the user's response to the server slow. One way for developers to mitigate the interface problems with this problem is by using remote scripting, a remote scripting that uses a DHTML combination containing Java applets to dynamically generate requests to update data to the server on existing pages.

In addition, developers can use (ie requests only) client script and XMLHTTP to send requests to server background data.

However, the implementation of these two methods is difficult, it requires very careful and efforts, especially the compilation.

Developers look forward to some changes in the original ASP.net release version, and they get some, such as server controls, ViewState, automatic postbacks (automated postback), and an event-based asp.net programming model that solves many of the problems. Especially smartnavigation (in IE applications only). But in order to implement Cross-platform applications, developers continue to rely on remote scripting. This problem has been radically changed in ASP.net v2.0 (Whidbey).



Whidbey support for customer callbacks



In the Whidbey version, the client can invoke the server method to submit the data and obtain the results without submitting the form. These calls you just write a few special code, using the background XML HTTP to implement the server request.



Figure I shows the application logic process.

You write a client function (step 2) that makes a request to the server, and defines a server event (step 1 c) to process the request. Callbackmanager is like a staging point, dealing with a sequence of steps 3 through 6. This includes the sending of requests from the client to the server and the return of data from the server to the client.

Another client function (step 7) handles the server's return information. You wrote two client functions to send a request to the server and process the server's return information.



Implementing queries
Suppose you need to create a page to query data from 3 database tables: Region, Country, and city. (See Figure 2)





This is a typical example of a "dependent list" problem. When a user chooses a region, the program should use the country in the region to bind the country list. Similarly, when a user chooses a country, the city list should be the only one that contains the selected country. (See Figure 2)


Of course you can use the normal postback technology to do this, but you have to endure the performance cost of redrawing the entire page every time you make a request to the server. However, because you can maintain all the page layout code, you can provide a better, faster way to implement this function, which is to use remote callbacks (callbacks), sending only the appropriate identities at a time and just getting the appropriate data.







Download this article code, code includes CALLBACK.SQL database script, used to build this article with those data. You can use SQL Server or the MSDE database. Run the database script first (you can use the other database if you want to change it as needed). Then start the Visual Studio.NET Whidbey build an example.

Create engineering, select template Type "asp.net Web Site" (see Figure 3). This creates a new page default.aspx. You can also rename it if you want.







Template selection: Select the ASP.net Web site project in the template selection dialog in Visual Studio


Add dropdown controls to the Default.aspx page as shown in Figure 4.



You can view and copy all the code from the <asp:table> included in the download code for this article.

In order to realize the function of remote callback, the ICallbackEventHandler interface must be implemented. Add the following code to the page.

<%@ Implements Interface=
"System.Web.UI.ICallbackEventHandler"%>
This is interface has a single public event definition so you must implement:

public string RaiseCallbackEvent (
String eventargument) {
Server Side handling here ...
}
A remote callback causes the client to produce raisecallbackevent. Therefore, you should process and return information based on the eventargument sent by the client. You can see from the method signature that this method parameter is a string and returns a string.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.