[Getting started with ASP. NET]
-- ASP. NET page model
A group of people who speak the same language plan to build a cloudification tower that goes directly to the sky to prove the power of ethnic unity. The tower will soon take shape. Now, the God of heaven can be shocked. He thinks that this person and God have become neighbors. How can he rule mankind? So magic disrupted people's language, making them unable to communicate, and the tower could no longer be built.
■ Human-Computer Interaction)
There is an article "write a program for mom" in the blog. It is said that the author often exhausted his mind to guide his mother in her first 50 s to complete operations such as copy, and finally made one for him with only two clicks.ProgramTo introduce the importance of the uidesign. Indeed, in terms of users, software is equivalent to N user interfaces. Most of them don't care about how many so-called advanced technologies are fascinating to developers. Simple, fast, and beautiful are all they need. The research field of human-computer interaction is playing around with these seemingly trivial things.
In the system design, the boundaries of the automatic system must be divided into two parts: manual operation and automatic system. User Interface ( U Ser I Nterface. Complete system input and output on the user interface: Collect User trigger events and related data, pass them to the system for internal processing, receive the processing results, and visualize the processing results. In enterprise-level C/S applications, the function of aspx and its background encoding files is simply one-to complete human-machine interaction. A beautiful web page is not all about the user interface design. It should look like a reception person with a good face and sweet voice, asking user needs in a whisper, and listening to user disorganized comments, patiently guide the user to complete the operation process, tolerate user errors, and accurately deliver the final result to the user-"Your account has only 0.4 yuan left, and the payment operation cannot be completed." In a word, we must fully understand and understand the great spirit of writing poems by Comrade Bai Juyi, so that our mother in her early 50 s can complete human-computer interaction happily.
■ Manual update-static ASP. NET Model
In the ASP. NET architecture, the ASP. NET page on the server corresponds to the HTML page of the client, which contains an interactive web form that inherits from the page class of the framework. The aspx file is a person, the temporary HTML file is a shadow, and the animation is a shadow. The two are combined into a complete user interface. The user performs various operations on the shadow, and the system processes the shadow through a person. The "request-response" Feedback Mechanism completes the image process between the two. The process is 8-2.
HTTP is a stateless protocol, so the Web server is a kind of students who forget to wait for a nap. When the response is sent, all request information will be discarded. This will affect the availability of the application. For example, if the user is required to re-enter all the information in dozens of input boxes due to a data verification error, even the mother's finger will send a protest. To make up for this defect, ASP. NET uses viewstate to completeStatus persistence. The principle is very simple. The server writes the page data in each HTTP request to the generated HTML file, which is included in the next page submission, as shown in the following example. In the ASP era, we used <input type = "hidden"> for manual implementation, while in. net, you will find that HTMLSource codeA _ viewstate label is automatically generated, and its value is the page data saved by the system.
<% @ Page Language = " C # " %>
< Script runat = " Server " >
Protected Override Void Onload (eventargs E)
{
Int Val = Int . Parse (_ sum. innertext );
_ Sum. innertext = (Val + 1 ). Tostring ();
Base . Onload (E );
}
</ Script >
< Html > < Body >
< Form runat = " Server " >
< SPAN ID = " _ Sum " Runat = " Server " > 0 </ Span >
< Input type = " Submit " />
</ Form >
</ Body > </ Html >
Viewstate reduces a lot of trouble, but there are also problems. By default, it is enabled. It collects all page information and shuttles back and forth between the two ends of C/S even if it is useless. A large body of Base 64 encoding often consumes a large amount of bandwidth, this vulnerability may cause system security problems.
The user will make various operations on the interface, and want to get a system response, these user interface operations are collectively referred to as. netEvent(EventThe system also generates events), and the corresponding system response is calledEvent Processing. On the login page in question 4, when a user clicks the btnlogin button, the btnlogin object is calledEvent Source) Shouted: "I have been clicked. After ten years, I have finally been clicked for the first time. 555 ~~~" However, the corresponding event handler is not defined for the button class. Who will complete the system's actual response?
When writing the login class, we have defined the member btnlogin_click method and want to complete btnlogin. click Event processing, But Ms engineers do not know its role when defining the button class, so a media is required to connect the two. At this time, we can't help but recall the delegate in "think 7 .. Net uses the eventhandler delegate as the media to connect the event source and event handler, and binds the two:
// This program is the login. aspx. CSCodeSegment and modified
// Eventhandler is the Public Delegate defined in the system namespace
// Sender is the event source object, and eventargs class is responsible for collecting event data
Public Delegate Void Eventhandler ( Object Sender, eventargs E );
// Login is a trusted class that completes the definition and link of Event Processing
Public Class Login: system. Web. UI. Page
{
......
// Login. oninit is a page-class protected method. Perform the initialization steps required to create and set an instance.
// The init event is triggered when the oninit method is called.
Override Protected Void Oninit (eventargs E)
{
// New system. eventhandler generates a delegated instance
// + = Completes the connection process of event processing delegate. A single event can trigger multiple processing programs, called multi-channel broadcast.
// Base. oninit (e) is used to call the method with the same name as the parent class.
This . Btnlogin. Click + = New System. eventhandler ( This . Btnlogin_click );
Base . Oninit (E );
}
Private Void Btnlogin_click ( Object Sender, system. eventargs e ){......}
}
■ kuaigo-Asp. NET Dynamic Model
before every HTTP request is sent, it is tragic! Login. the ASPX page requests to package the URL and related data on the back, and carry your own IP address ID card on your chest. Starting from the client browser, the requests will jump over the various obstacles manually created by China Telecom Netcom and climb the snow mountains to the grass, walking to the IIS door of the web server, I was about to get excited for a while. When there were tens of thousands of long request queues standing at the door, and there was often a little starving, it finally fell down.
login. the ASPX page request is sent to the httpruntime instance. The httpruntime instance will:
• get an HTTP application object;
• get the HTTP application object to read the configuration file;
• the HTTP module instances provide session maintenance, verification, configuration file maintenance, and other services respectively.
• the HTTP handler interface instantiates a specific page class for processing.
Login is a worker in the HTML page production workshop. Every day, he is responsible for creating HTML-encoded login. aspx pages for customers according to strict standards and fixed procedures. One morning, login was drinking coffee in the hard drive. Uncle httphandler, the big-fat supervisor, informed him that he was about to start work immediately.
Today is the first time he enters the memory, so he first prepares the page framework and all control parts and sets their default status. Then, he strictly presses Oninit Method After the init event is completed, _ viewstat will be searched in the page request. Read and decode the data if they are found, and update the status of the control to accurately reflect the status of the corresponding elements on the client;
Then he took out Onload Method The operation manual is used to handle load events. It then handles a series of triggered page events. If the page is being sent back, it also includes user-triggered events.Onprerender Method The processed prerender event can change the Page Submission method, and then save the current page status to the new view status.
After all the operations are completed, the HTML encoding file can be generated. During this process, override can be used) Render Method Append some HTML code for the final modification of the page.
Finally, login releases all the files, graphical objects, database connections, and other key resources in use, and runs out of memory in a rush. "It's so boring !" He whispered while going out.