Server-side-centric asp.net ajax mode (Part 2

Source: Internet
Author: User

In the last article, the server-centric ASP.net AJAX model (part 1-behavior), we explored the more Easy-to-use Behavior model. It is easier to use because it does not involve interacting with the original page processing process, and even if the access network is a stand-alone web Service (including [WebMethod] on page), the design of the page processing process is absolutely orthogonal. But sometimes what we need is the interaction with the page process, and we have to use control that is tightly coupled to the server side, which is what this article is about.

Under the basic asp.net AJAX framework, there are three ways to do control-based AJAX operations, which are UpdatePanel, ICallbackEventHandler, and IScriptControl, respectively. Let's take a look at their features and use scenes separately.

UpdatePanel

UpdatePanel is one of the most easy-to-use scenarios for interacting with server-side logic, and cannot even be called interaction-you don't need to touch any client logic at all. A server-side operation, after UpdatePanel "hijacked" into a client operation, and this client operation and directly call the corresponding server-side operations, it is so simple.

If you use UpdatePanel to make a selection dialog with a branch, how should you design it? The idea does not run to the client's confirm method, that can too revolve, or say too asp.net ajax. With UpdatePanel, it should adhere to its philosophy, all client operations are illusions, all operations are actually done on the server side, including the selection dialog box. To do as asp.net, I will make a selection dialog control, it is the essence of a floating layer simulation of the dialog box, which is implementation details, we do not pay attention to. The point is that the branching logic of this selection dialog is done entirely on the server side, and after Async postback, the server side decides how to trigger the event based on the data that is submitted back. The logic of the entire branching selection is embedded in the page processing process, eliminating the need for cookies or sessions to be used as a transit medium for data, avoiding the tight coupling of the page processing process with the data in the larger scope.

UpdatePanel applies to logical full server-side development, and I recommend using UpdatePanel to put all the logic on the server side, and not to write code that mixes server-side logic with client logic. Some people will say, you see Lao Zhao very like to move that Sys.Net.WebRequestExecutor to change updatepanel behavior ah, but in fact this is part of layered design thought, he moves that thing to change is a layered logic, As long as the interface between layer and layer is unchanged, the implementation can be designed on demand. But if you use a UpdatePanel, and then use a cookie or session to pass the value, which spans the n layer, adding a lot of coupling.

ICallbackEventHandler

As for ICallbackEventHandler, I've said countless times, the point is that you have to think with the page process, as long as you understand the page process, you can see why ICallbackEventHandler in. NET There is only one method in the Framework 2.0 Beta2, and the RTM has to be split into two methods. can refer to "asp.net 2.0 clientscript Callback" Specifically, I will not repeat.

What if you use ICallbackEventHandler to implement a selection dialog with a branch? Like using UpdatePanel, I still make a selection dialog control, and the control inherits from ICallbackEventHandler. When writing JavaScript for this control and implementing the ICallbackEventHandler interface, I make sure that JavaScript gives the correct invocation parameters to the callback, and it is simple to receive these parameters in the implementation of the interface method and then trigger the correct event. Like UpdatePanel, do not deviate from the ICallbackEventHandler design idea, its processing process must be merged into the page processing process, your control must be designed this way.

And under what circumstances do you choose ICallbackEventHandler? If you have a lightweight Ajax operation, but using UpdatePanel to update the entire area of HTML overhead, then you can consider using ICallbackEventHandler. Of course, the premise is that you understand control development and JavaScript.

Related Article

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.