A year ago, when I got a PHP program named Twig, I immediately was discouraged by the author's OOP. It is hard to imagine all the features in Twig (in trouble, email, personalization) all in a PHP file (Index .PHP3) is executed in the implementation, which benefited from the author's idea of using the program code and the page architecture, but I also see although the author has made great efforts, but due to the limitations of PHP, the program did not really do Separation of code and architecture, index.php3 this primary file is much more powerful because of much functions to be executed, so that the entire file is still very zero, I spent half a month. Time, you really understand the architecture of the program, analyze the bitterness of the code, no one can know (然 tears ...).
The TWIG program has a great impact on my future programming, but even such a work, there is still no situation in which the program code is mixed with the HTML code.
The separation of program code and page architecture is a dream of web programmers for many years. Before ASP.NET appears, whether it is ASP, PHP or JSP, the program code and HTML code are mixed together, this approach, although it is praised in the initial period of Web technology, but over time, its drawback It is increasingly obvious. When the program code is very long, the HTML code is mixed, and the readability of the program has become very poor, which is unable to distinguish the page architecture that the program really wants to represent.
The new technologies ASP.NET truly code separation through the CodeBehind, User Control, and Custom Control. This is an amazing progress, and everyone can see how clear the structure of the ASP.NET program after separation of the code is here.
The flying knife take it to everyone to demonstrate their specific implementation methods, let's take a look at the functions you want to achieve.
For ease of understanding, the page designed here is simple, the page is divided into three main parts, the head contains an ADROTATOR control (to display an advertisement) and a Label control (to display the current ad link address); the middle is a landing Page, including two TextBox controls (used to enter usernames and passwords, one Label control (display login is successful) with a Button control (as submission button); bottom contains two Label controls (display the current user name, respectively User rights).
Friends who are familiar with Asp.Net, immediately realize that the header must have an onadcreated event to display the corresponding link in the Label control; and the central part is an OnClick event. deal with.
1 Codebehind
First we see how to use the CodeBehind method to implement the separation of the code and the page architecture, the source program given below is the primary ASP.NET program --Example1.aspx:
<% @ Page src = "cseventhandle.cs" inherits = "ASPCN"%>
hEAD>