Microsoft ASP. NET 2.0 AJAX sword ~ Atlas Framework
(The author is a senior Microsoft expert and cannot be remembered)
Preface
Since 2002. NET version 2002, Microsoft's Web technology officially moved from ASP to a new ASP. NET milestone, epoch ASP. in just a few years, NET has become a popular mainstream. It successfully captured the focus of information media and web application developers and won the favor and appreciation of everyone. At the same time, it has created a global market. NET boom, when you see this article, the next generation of VS 2005 and ASP. NET 2.0 has been officially published (US 11/7), due to the previous generation of ASP. NET 1.0 technology success, it is natural that everyone has long led to look forward to ASP. NET 2.0 rich controls and underlying functional integrity can come soon, but if you only know ASP. NET 2.0, VS 2005 products or technologies, you are currently in ASP. NET technology crisis, because there is a huge sword flying behind your back, a careful Puncture of your strong technical armor, is it so exaggerated? It's no exaggeration! This is because of ASP. NET beginners only need to skillfully use this sword, in some ASP. NET web page design environment can beat the powerful web page programmers, and experienced web page programmers do not know where they were defeated, what is the name of this sword flying from the void? It is called "Atlas" and is an AJAX Framework. mastering this sword is like mastering the Qingming sword in the movie "Crouching Tiger, Hidden Dragon, if you can beat the most powerful competitor (a metaphor for the difficulty of web design) between the two, the following explains what AJAX is and what Atlas Framework is.
AJAXAsynchronous Technology
AJAX is composed of the starting English texts "Asynchronous JavaScript and XML" and is an Asynchronous technology, on the surface, it seems that "Asynchronous", "JavaScript", and "XML" are three things. It seems nothing amazing !? People have played games more or less. People who write web pages know JavaScript, some are familiar with JavaScript, and some are familiar with XML. As for synchronization, it does not seem important, this was the first time I saw AJAX a few months ago ~ Should I have a new bottle of old wine or hot fried rice? So I took a glance at foreign articles and rushed to bring them back. However, after three days in a row, the word "AJAX" was put forward by a bunch of experts on Microsoft's MSDN Blog in the United States one after another, and I felt that it was wrong, there is actually a technology that I don't know (if AJAX is very important and powerful), So I went deep into Study's AJAX principles and technology. OH ~ My GOD! It's pretty powerful.
We all know that JavaScript is the old king of the Client. NET is the ultimate overlord of the new generation of Server. In most cases, the two are almost irrelevant. Because of their respective operations, AJAX does not seem to have Power in the form of Asynchronous JavaScript and XML, the key point is that AJAX can skillfully combine Client-side and Server-side technologies. Once the Client-side can invoke the Server-side applications, you will find that the strength of the designed web page will be endless, this uses the traditional ASP or ASP. NET seems "impossible", because the Web is stateless, so there will be no online between Browser and Web Server, only the so-called Request and Response behavior, in addition, the memory management space and mode of the two are basically two worlds, so JavaScript and. NET Code cannot be effectively integrated. Possible, but with the power of AJAX asynchronous mode, JavaScript can freely call C # and VB. NET or Web Service, and then can return. NET type objects such as DataSet for JavaScript processing; in addition, AJAX asynchronous technology only needs to pass a small amount of data back to the Server for processing, unlike the current method that must be used to send the entire page back to the Server for processing, from then on, I can Say bye with the Postback cool, which is incredible! (But it does not mean to discard Postback, but to use AJAX more flexibly as needed ).
OK! To put it bluntly, how can we use AJAX? First of all, I want to clarify that AJAX is just a kind of "concept", which means that AJAX can be called by using three types of technologies: Asynchronous JavaScript and XML, instead of a specific component or product, I currently know that there are several ways to implement AJAX:
· Self-built AJAX by hand: the disadvantage is that it is too difficult and time-consuming for most people and lacks AJAX knowledge.
· Using Callback: the disadvantage is that only ASP. NET 2.0 is supported, and the functions are still incomplete.
· Use ready-made AJAX Library: after all, the Library is only a Library, which is slightly inferior to the Framework, but the advantage is that it can be obtained free of charge and is applicable to ASP. NET 1.0 and 2.0 are a good way.
· Microsoft Atlas Framework: the advantage is that it is positioned at the Framework level. The preliminary planning and design Scope is relatively complete, and both Client and Server are taken into account. Unfortunately, only ASP. NET 2.0 is supported.
AJAXSimple Example
To let everyone know what AJAX is, the following is a manual example of AJAX (meaning that no Library or AJAX framework is referenced). This example is quite easy to understand, the main function of AJAX is to monitor Web server resources or performance changes in real time through the Client Browser. Once you have done the following examples, you can understand how powerful AJAX is in Web development.
Step 1: create a Web project
First, create a WEB project in VS. NET 2003 (or VS 2005). The project name is "SimpleAJAX", or you can directly create it in a notebook without VS development tools.
Step 2: Create a Client page
Add a Client-side "client.htm" to the Web project and set this page as the start page. This page sends an asynchronous call request to the Web server webpage, the program code is as follows:
<! Doctype html public "-// W 3C // Dtd html 4.0 Transitional // EN ">
<Html>
<Head>
<Script language = "javascript">
Var XmlHttp = new ActiveXObject ("Microsoft. XMLhttp ");
Function sendAJAX ()
{
XmlHttp. Open ("POST", "Receive. aspx", true );
XmlHttp. send (null );
XmlHttp. onreadystatechange = ServerProcess;
}
Function ServerProcess ()
{
If (XmlHttp. readystate = 4 | XmlHttp. readystate = 'complete ')
{
Document. getElementById ('namelist'). innerHTML = XmlHttp. responsetext;
}
}
SetInterval ('sendajax () ', 1000 );
</Script>
</Head>
<Body>
<Div id = "nameList"> </div>
</Body>
</Html>
Figure 1 Client.htm page
Step 3: Create a Server-side processing program
In addition, add a Receive. aspx webpage (including. cs) to the project. The program code is as follows:
Using System;
Using System. Collections;
Using System. ComponentModel;
Using System. Data;
Using System. Drawing;
Using System. Web;
Using System. Web. SessionState;
Using System. Web. UI;
Using System. Web. UI. WebControls;
Using System. Web. UI. HtmlControls;
Using System. Diagnostics;
Namespace SimpleAJAX
{
///
/// Abstract description of Receive.
///
Public class Receive: System. Web. UI. Page
{
Private void Page_Load (object sender, System. EventArgs e)
{
PerformanceCounter myMemory = new PerformanceCounter ();
MyMemory. CategoryName = "Memory ";
MyMemory. CounterName = "Available KBytes ";
String txtResult = "--> available server memory size:" +
MyMemory. NextValue (). ToString () + "KB ";
Response. Write (DateTime. Now. ToLongTimeString () + txtResult );
}
}
}
Figure 2 Receive. aspx page
Execution result:
After execution, it takes about 5 seconds to start the PerformanceCounter object, and then the Server available memory changes can be obtained every second through AJAX. Of course, some people may think of using the Server side Timer, but that method will cause the Server's Loading to surge. If there are too many people, it may take your Server down. However, AJAX is extremely flexible and flexible, with AJAX, you can detect database or event changes in real time and display changes on the webpage in real time. For example, I have ten WEB servers (only Port 80 is enabled ), in this way, AJAX can monitor the CPU, memory, and network traffic of ten servers on a single webpage. Is it very attractive.
Figure 3 Server Memory changes per second
Program description:
This application has the following features:
1. how can JavaScript be called. NET Server method or Web Service, if the traditional Web page program concept seems to be "impossible", because the Client side JavaScript can not directly refer to the Server side.. net clr memory address.
2. in the past, some people may have tried to implement Server Timer to achieve the same effect, but those who have done so should feel how heavy and costly the system resources are on the Server side, if multiple users are provided at the same time, the Server may be more burdened.
3. the AJAX program can call the Server application or Web Service without any trace, and process the returned data to quickly update webpage data, which makes it easy to forget that the Client and Server are separated.
4. There will be a preliminary explanation of XMLHTTP operations later.
To help you understand the blueprints and policies of AJAX and Atlas Framework correctly, the following are two articles about Microsoft:
1. Understand AJAX applications and ASP. NET Atlas Framework
2. this article introduces traditional ASP. NET web application development and limitations, and then introduce the overview and advantages of AJAX technology, while Microsoft proposed a new Atlas Framework for AJAX technology to simplify complicated AJAX program development, finally, the architecture and functions of the Atlas Framework are briefly described.
3. Overview of ASP. NET Atlas Framework
4. this article exposes the functional design and overall overview of the Atlas Framework, and explains the functional architecture of the Atlas Framework Client and Server, this is a clever strategy for implementing both Client and Server functions in Atlas, if you only consider Client-side JavaScript calls or page processing, it will definitely limit the development of AJAX applications and make full use of ASP. NET 2.0 all the advantages of the Server, and the program development personnel must be constantly entangled with the Client front-end call or data processing tedious work, this approach will be greatly reduced, fortunately, the Atlas Framework took the right path from the very beginning, and developed AJAX applications or functions through the Atlas control, several lines of program code can be used to complete the web page functions that previously took several weeks or did not start with (such as automatic completion of web pages ).