Use user controls in ASP. NET

Source: Internet
Author: User

【Abstract】 the user control provided in ASP. NET can solve the code reuse problem that cannot be solved in ASP, and facilitate the error check in debugging. This article explains how to implement the user control and how to implement a user control routine. It further verifies the feasibility and effectiveness of using the user control to solve code reuse.
[Keyword] code reuse, user control, @ Register command
ASP. NET provides a better code separation solution than traditional ASP. In traditional ASP, Server. the code of the ASP file or transaction object component executed by Execute is separated. Generally, the code can only be separated into several files, and then the "include" method is used. This method causes multiple copies of the "include" file in the memory (one copy is generated every time the file is referenced), which increases the burden on the system and is therefore not feasible. Using Server. Execute may be somewhat different, but it is not possible to pass the additional query string parameters to the ASP file being executed. Using components may be the only good practice. In ASP. NET, in addition to the "include" (not recommended) and transaction object component methods, you can also use two new technologies: code-behind class and WEB user control.
The code-behind class can effectively split the HTML code of the client and the event processing code of the server. Splitting these two parts of the Code is conducive to tracking the program during debugging, because at that time there is no need to switch back and forth between the Code Implementing the user interface and the transaction logic code. In addition, if the user interface and transaction processing in the project are developed by different groups, the code-behind class can be used for independent debugging. The code-behind class is used to separate the user interface code from the transaction logic code to simplify code integration and maintenance. The following describes the user controls to process code separation from the perspective of code reuse.
1. User Control Overview
User Controls enable programmers to easily divide and reuse the public UI functions across ASP. net web applications. Similar to WEB forms pages, programmers can use any text editor to create user controls, or use code hiding to develop user controls. In addition, like WEB forms pages, user controls can be compiled and stored in the server memory during the first request, thus reducing the response time of subsequent requests. However, unlike WEB forms pages, user controls cannot be requested independently. user controls must be included in WEB forms pages before they can be used.

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.