Implement CSS based AJAX development with. NET (1)

Source: Internet
Author: User
Tags hash http request implement interface net string sort split
Before I introduced my. NET version of the AJAX Library (a simple AJAX processing library under. net), now I want to introduce a development pattern: style-binding-driven development.
The style driver is my own name, (I don't know what it's called, hehe) to differentiate between current request-driven development (such as struts, webwork, etc.) and event-driven development (such as asp.net, JSF, etc.).
Body:
1 Introduction
First, let's take a look at the traditional Web development process:
• Request-driven: The most common type of web framework implements a request-driven process. An HTTP request has recently been a generic distributor servlet
(Dispather Servlet) analysis, which is then distributed to a corresponding application processor. The processor sequentially handles UI-specific control logic, calling business objects and processing
Session state, prepare a model, and then forward to the view.
• Event-driven: The event-driven framework is designed to move well-known event-driven patterns in desktop UI programming to the Web environment. It is characterized by;
Forms submit to URLs, how to map URLs to controllers these issues do not care; In the event-driven framework, the form component is associated with the listener, and the listener
Call via event. Moreover, such frameworks usually do not intend to implement pluggable attempts to render to a particular model object, but rather to treat a Web page as a column-writing interface group
components, each component can maintain its own state and know how to present itself, and may even use different interface skins.
From the above you can see that one of the traditional MVC architectures is development, and a page-centric rapid application development (RAD) has its own benefits.

Style-driven development is a simple encapsulation based on request-driven development or event-driven development, which incorporates both conceptual advantages at the interface level, with the most foreground
The interface layer is based on the CSS style or HTC Event binding interface elements to perform the corresponding background business, so as to execute the corresponding request, the purpose of handling the corresponding events

The advantage of style-driven is that you can achieve special kinetic energy and specific business processes by simply giving the foreground element a specific style, reducing the amount of coding and compiling
Times, with the "once written, everywhere binding" characteristics. More complex than the traditional development of reuse. Especially in the way Ajax is doing today, in the request-driven framework or event
Drive an existing framework based on the use of style bindings to develop AJAX-enabled applications, you will find that your AJAX program development efficiency will improve a lot, especially when repeated should
The same (or similar) background logic is more obvious, and similarly, the development of style binding has great advantages for service-oriented development.

2 style-driven development based on ASP.net

Style-driven operations are not dependent on the background implementation, ASP.net runat=server can magically move the foreground elements into the background elements, but this transformation
Depending on the particular element and the background, such as <input Type=text runat=server>, it does extend the INPUT element into a server element that can be used in the background
, but for the backstage he will be in the page corresponding to the specific processing, and input type=text can only be input type=text can not expand their
The function. Style driven can be all elements, controls or controls in the elements of the use of JS powerful features in the foreground to the function and effect you want, and then into
Original request or custom request, thus make up for some deficiencies of asp.net, "write, Everywhere Binding" features also for us to save more than one page class write duplicate code
Many troubles.

Perhaps you would say that there is no user control, I am sorry, the user control is heavily coupled to the front, you can get it to a project may not be useful.

What about the Web control library? Although it can be reused, it is not coupled with the user control, but the limitations are too strong, the complexity is high, I think call a common programmer to write a band-mode
The Datagird of the board item can be sorted, can be deleted, modified, move up and move down the control that can view the details is a lot of trouble.

Another said, really stupid, I directly dragged a DataGrid and then on this basis to add a button, template columns, sorting, detailed connection good ah, but also used deliberately to make a
Control? I'm sorry to tell you, if it is 1000 datagird, each has one or several of these functions, then you have enough writing in the background, even if you abstract
Out of a layer, encapsulated a specialized Datagirdbuilder class, also complex enough, a variety of overloaded methods, Halo.

Then the development of the use of style binding is simple, give datagird a sort of style (such as Cssclass=sort), the background of a few lines of code, or simply do not write (
Your preparation is sufficient), and then add a column to the Delete button (such as one of the column ItemStyle cssclass= "delbtn"), you can,
The other DataGrid does not need to be sorted, so the style is removed. And then in the page class dry quietly. The elements that change after the style is bound are passed to the unified business object for processing,
Everything is a rule.

3 implementation
Using the Ajax libraries I've done before, and combining JavaScript scripts to build a library like this is no problem. Naturally, just like cooking, it's a very good choice.
Important, here I'm going to choose from the event Action Scripts Library (Common.js) from Dean Edwards and Tino Zijdel, and Neil Cro~~~~y's style base Operations library (
Css.js) To do our delicious, oh, of course, there is the famous Prototype.js library.


Well, the production process of the front desk is basically finished.
Then I used the AJAX library I did a while ago.
The assumption is to delete, querystring:command=delrow&js the generated parameters ...
The background call AjaxDelRow.cs

protected override void Doajax ()
... {
Collect parameters
String parlist = Request. params["Pars"];
string[] Paritem = parlist. Split (' | ');
Hashtable hash = new Hashtable (Paritem. Length);
for (int i=0;i<paritem. length-1;i++)
... {
string[] Paritempart = Paritem[i]. Split (' ^ ');
Hash. ADD (paritempart[0],paritempart[1]);
}

BOOL isdeled = false;
string table = Request. params["Table"];
Source of Judgment
if (table!=null)
... {
if (table. Equals ("Dgbigclassmanage"))//datagrid ID number
... {
Call the DAO that corresponds to the business look to remove
hash["0"] is the No. 0 column of the DataGrid, assuming that the No. 0 biography comes with the ID value
isdeled = (new BusinessFacade ()). Deletebyid (hash["0"]. ToString ());
}
if (isdeled)
... {
Output ("true");
}
Else
... {
Output ("false");
}
}
Ajaxdelrow production process Please refer to the Simple AJAX processing library under. Net



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.