Asp. Separation of program architecture and program code in net

Source: Internet
Author: User
Tags mixed
A year ago, when I got a PHP program called Twig, was immediately impressed by the author OOP programming ideas, it is difficult to imagine Twig all the functions (calendar, mail, personalization) in a php file (index.php3) executed, This is because the author used the idea of separating the program code from the page frame, but I also see that despite the great efforts of the author, the program does not really separate the code from the architecture because of the limitations of PHP. Index.php3 This main file because there are too many functions to perform, so its require module file is quite many, to make the whole file still seems very messy, I am ignorant, then spent half a month time, just really understand the framework of the program, analysis of the pain of the code, no one can know AH (sadly tears ......)。
The Twig program has a big impact on my subsequent programming, but even this kind of work still doesn't get rid of the mix of program code and HTML code.
The separation of program code from page architecture is the dream of web programmers for many years. Before the asp.net appeared, whether ASP, PHP or JSP, program code and HTML code are mixed together, this approach, although in the early days of the Web technology was praised, but over time, its drawbacks are more and more obvious, when the program code is very long, the HTML code and its mixed , the readability of the program becomes so poor that it is impossible to distinguish the page architecture that the program really wants to represent.
The new technology asp.net the code by means of codebehind, user control, and custom controls (named Control). This is a remarkable improvement, and you can see how clear the structure of the ASP.net program is after separating the code in this article.
Flying knives here to show you their specific implementation methods, we first look to achieve the function.
For the sake of understanding, the page designed here is simpler, the page is divided into three main parts, the head contains a AdRotator control (for display ads) and a label control (used to display the current ad link address); The middle is a landing page, including two TextBox controls ( Used to enter a username and password respectively, a label control (showing whether the login was successful) and a Button control (as the Submit button); The bottom contains two label controls (the current user name and user rights are displayed, respectively).
Familiar with ASP.net's friends, you'll soon realize that the head because the AdRotator control is used, there must be a onadcreated event to display the link in the Label control, and the middle is bound to have a onclick event handling because it is a submit button using the button control.
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.