ASP. NET custom controls are compiled server-side controls that encapsulate user interfaces and other functions into reusable packages. Compared with standard ASP. NET controls, custom controls have no difference except that they are bound with a different tag prefix and must be explicitly registered and deployed. In addition, custom controls have their own object models that can trigger events and support all design-time features of Microsoft Visual Studio, such as attribute windows, visualizations, property generators, and toolboxes.
A custom control is a class that inherits the base class of a control. You can use either of the following methods to create a custom control. If you find that an existing control only meets some requirements and lacks some key features, you only need to generate a new class from the control class and expand it as needed. If the existing Server Control cannot meet the requirements, consider the following. web. UI. control class or system. web. UI. webcontrols. the webcontrol class inherits from the control class, and some style features are added.
All custom controls are still displayed to users on pages mixed with HTML, CSS, and Javascript. Therefore, when developing custom controls, you must consider whether the existing web page technology can be used, if a feature cannot be implemented in a pure HTML environment, the custom control cannot do the same.
The namespace that is frequently used when developing custom controls is as follows:
- System. componentmodel -- provides a class for implementing components and controls during runtime and design. It is often used to set the features of custom controls or perform type conversion.
- System. Web. UI -- contains the basic class of ASP. NET Server controls. The control class is located under the namespace.
- System. Web. UI. webcontrols -- contains the class for creating ASP. NET Server-side controls on the page. Common buttons, labels, and textbox classes are located under the namespace.
- System. web. UI. htmlcontrols-also contains a series of server-side controls. web. UI. the difference between webcontrols is that the classes in the namespace are directly mapped to some HTML tags, and these classes are prefixed with htm.
ASP. NET Custom ControlsArticle
Preface
Simple star control on the first day
Star controls with custom styles the next day
On the third day, use the star widget in the control status.
Fold panel custom controls on the fourth day
Star controls that can be scored on the fifth day
Star controls that can be bound to data sources on the sixth day
Develop list controls with rich features on the seventh day
Metric days: displays the data binding controls for multiple entry star rating
The ninth day custom gridview
Datalist that implements the paging function on the tenth day
Download all source code
Download this series of articles in PDF