Comparison of user controls and custom controls and their application in projects

Source: Internet
Author: User
Tags abstract comparison config modify query relative visual studio
Comparison | control | Project user control and custom control comparison and application in project


This document describes the basic concepts of server controls, as well as a comparison of user controls and custom controls in terms of deployment, creation, content and layout, design-time behavior, performance, and so on, and then give a recommendation for server control use in project development, and finally give an example of the creation and invocation of a user control. Keyword server control server controls user control, ASP. NET server control (a generic suffix named. ascx file) custom control, ASP. NET Server space (a general suffix named. DLL files) deployment deployment, distribution of programs design attributes RAD Rapid Application development Modify resume version number version finish date author modify content Description modification section involves chapter

1. Knowledge background

1.1 Server Control Introduction server controls are components used in pages to define the Web application user interface. Server controls are the basic element of Web Forms programming mode. They form the basis of a new, component-based, intuitive form program that simplifies the development of a Web user interface. This is similar to the method used by traditional RAD development tools such as Microsoft Visual Basic/borland Delphi to simplify Windows Forms programming. From a higher level, server controls provide the Web application and the abstract concepts implied by the presentation Technology 1.2 server control features and capabilities

1: Server controls hide potential inconsistencies and complexities in technology, creating an intuitive and simple programming model for Web developers

2: Server controls hide the differences between browsers and viewing devices, including different versions of browsers that a target Web application might need. Browser Controls provide the ability to display content for the target browser.

3: Server controls play the role of the actual component, providing the same benefits that can be obtained in the component's application cooperation with other classes.

4: Server controls Manage State by return (postback) and round trip (round-trip)

5: The server control contains the return data that handles the relevant Web request and the logical model that the Web Developer handles user input and user actions in its server-side code.

6: The server control provides a data-binding model.

7: Server controls provide a variety of mechanisms for developers to customize their own page generation (rending).

8: Server controls are configurable at the machine level (through Machine.config files) or at the Web application level (through Web.config files).

9: In a visual design-time environment such as visual, server controls provide a rapid application development (RAPID application Development,rad) environment

2. Why you write custom server controls

Although standard server controls can solve the most common application scenarios when it is not exhaustive. In fact, there are many scenarios that cannot be solved directly with these controls. For example, Standard ASP. NET server controls do not solve image mapping, mapping, and so on. Here are a few reasons to develop server controls:

1: Encapsulate the application in a reusable and intuitive form of abstract concepts in multiple Web applications

Order logic.

2: Create a commercial component class library similar to the active controls and Delphi in Visual Basic

The VCL control in.

3: Provide a clear mechanism for the division of labor in large work teams. For example in the work team

Developers can design and implement application user interface development tools to control

Grouped together.

3. Similarities and differences between user controls and custom controls server controls are divided into user control models and custom controls, and in general, the user control model is suitable for creating internal, application-specific controls, while a custom control model is better suited to creating generic and redistributable controls.

Here are 6 ways to illustrate their similarities and differences.

3.1 department when choosing between two control models, deployment is the most important consideration, and the custom control model takes the form of accessories that most applications can use (. DLL, designed to create redistributable components. The user control model is designed for the case of a single application. The user control must be deployed in the form of a source code (. ascx files), these requirements have side effects that increase maintenance costs.

3.2 Creating a custom control is not the same technology as creating a user control, which is used by a custom control. NET programming languages are created by writing a managed class that derives directly or indirectly from the System.Web.UI.Control class. There is no provision designer support for creating custom controls. However, the user control class is indirectly derived from System.Web.UI.Control, and the user control is created declaratively in the form of an. ascx file, similar to the way you design and develop a page (easy to design and debug).

3.3 Content and layout depending on the creation mechanism, user controls and custom controls provide different content and layout support custom controls are very useful for dynamic content that is represented in a programmatically generated layout. For example, a data-bound control with dynamic rows, a control tree of a dynamic node. The layout of the user control is in the. The ascx file is declared when it is created, so the user control is the best choice when the relative static content of the layout needs to be fixed.

3.4 Design period behavior Currently, Visual Studio. NET provides quite different design-time capabilities for custom controls and user controls. Visual Studio. NET provides a large degree of design-time support for custom controls, such as the ability to support design-times properties, methods. Visual Studio. NET has very little design-time support for user controls. The user control does not display properties and events in the Properties window, nor can it be placed in the toolbox.

3.5 Performance Although custom controls and user controls follow different creation models and have different characteristics, However, both of these controls are indirectly derived from the same base class (System.Web.UI.Control), and the user control is declared when implemented, and the user control is parsed and compiled into the accessory as a normal server control when it is first used in the page. Since then the behavior of the user control is like any other compiled (or custom) control, so the performance difference is not very large, and there are other ways to consider how to choose the two kinds of controls.

4. Recommendations for server control development scenarios recommendations for server control development

5 Development of user controls The following is an example to describe the development process of a user control. (by converting a partial page of an existing into a user control model).

Query_uc_common.ascx Source Files

Pages to custom controls that need to be modified

Note: The page to the custom control needs to modify the part

1: Delete tags
2: <%@ Page language= "C #" Classname= "Requiredtextfield"%> this is <%@ control language= "C #" Classname= " Requiredtextfield "%>

3: Save the file as. ascx file can

Note: The description of the user control is invoked on the page

1: The declaration statement for the user control,

2:tagprefix:tagname combines to generate a label that is associated with a specified user control when the server resolves, and this combination must be unique for each user control that is registered. 3:src= "Query_uc_common.ascx" is a user control at the location, can be a relative path or an absolute path, but it must be accessible to users of this page because of this universal query display and print the user control involved in too many knowledge points, I will write a special analysis report, Talk to everyone!

Screenshot of the interface is as follows:

Query Settings interface filter display fields

6 reference materials


3:developing Server Controls

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: 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.