"Digest" ASP. NET can solve the problem of code reuse which cannot be solved in ASP, and make the error checking in debugging work more convenient. This article through the user Control realization method explanation and a user control routine realization, further verifies the use user control solves the code reuse the feasibility and the validity.
Keyword code reuse, user controls, @Register directives
Asp. NET provides a better code-splitting scenario than the traditional ASP. In a traditional ASP, you will use the server. The code for an ASP file or transaction object component executed by execute is separated, typically separating the code into several files and then using the "include" method. This method will cause a duplicate of the "include" File in memory (a copy is generated every time the file is referenced), thereby increasing the burden on the system and therefore not feasible. Use the server. Execute may be a bit of a change, but you cannot pass an additional query string parameter to an ASP file that is executing. Using components may be the only good practice. In ASP.net, there are two new technologies that can be used, in addition to the use of "include" (which is not recommended) and transaction object components: Code-behind classes and Web user controls.
Using the Code-behind class can effectively separate the client's HTML code from the server-side event-handling code. The separation of these two parts of code is useful for tracking programs when debugging, because there is no need to switch back and forth between the code that implements the user interface and the logical code of the transaction. Also, if the user interface and transaction processing in a project is developed by a different team, then using the Code-behind class will enable the two parts to be debugged independently. Using the Code-behind class separates the user interface code from the transaction logic code, making the code integrated and maintainable easier. The user controls described below deal with code separation from the perspective of code reuse.
1, User Control Introduction
User controls make it easy for programmers to divide and reuse common UI functionality across ASP.net Web applications. As with Web Forms pages, programmers can use any text editor to author user controls or use code-behind classes to develop user controls. In addition, as with Web Forms pages, user controls can be compiled and stored in server memory on the first request, thereby shortening the response time for subsequent requests. Unlike Web Forms pages, however, you cannot request a user control independently, and the user control must be included in a Web Forms page for use.
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