ASP.NET control model comparison and the selection of the base class when creating a custom control

xiaoxiao2021-03-06  52

Comparison of ASP.NET control models

ASP.NET provides two control models for user controls and custom controls. In general, the user control model is suitable for creating application-specific controls, while custom control models are suitable for creating universal redistributive controls. From a deployment point of view, custom controls are deployed in binary forms, while user controls must be deployed in the form of source code. The user control is derived from the System.Web.ui.UserControl class, supports the development of the ASP.NET page to develop, and the custom control class is derived from the Sytem.Web.ui.Control class directly or indirectly, and it is not created in VS. Define the designer support for the control. Custom controls provide rich design period support, and user controls have little design. On content and layout, custom controls can show any dynamic content, and user controls are compared to static content. Although the model is different, both types of controls are derived from the System.Web.ui.Control class. Although user controls are declared, the user control will be parsed and compiled into the accessory when the user control is declared. Since then, the behavior of the user control is just like any other compiled (or custom) control. Therefore, there is no significant difference between the two models, and the performance is not the main factor of the selection model, and the development model should be selected based on other factors such as deployment, creation, or design period.

Choice of the base class when creating a custom control

If the control requires text (such as XML or WML) or an unacceptable HTML text other than HTML, you should choose from the Control class. If you only need to generate a pure HTML text and do not provide the user's functionality to modify the generated element, you should also choose from the Control class. The Control class only provides all lifecycle events in the ASP.NET page generation process. If you want to generate visual HTML text, you should choose from the WebControl class, which provides more built-in UI properties. In actual development, you should give priority to the existing ASP.NET controls, multiplexed the existing features, rewrite, or add other features in which the existing features, rewrite, or add other features in which the existing functions are required.

转载请注明原文地址:https://www.9cbs.com/read-117150.html

New Post(0)