From the inheritance relationship, ASP. NET Server controls are classified into four categories:
ASP. NET Component Design-ASP. NET Server controls 1. User Controls
Similar to page, there is basically no need to program. You can use An aspx page as a reusable component.
ASP. NET Server controls 2. LiteralControl
ASP. NET compiles all HTML elements and readable text that do not need to be processed by the server into an instance of this class. For example, HTML elements that do not contain runat = "server" attribute/value pairs in the start tag are compiled into LiteralControl objects.
The behavior of the text control is the same as that of the text control, which means that the text control can be extracted from the text control and removed from the ControlCollection of the parent server control through the Controls attribute of the parent Server Control. Therefore, when developing custom controls exported from the LiteralControl class, make sure that the control executes any required preprocessing steps by itself, rather than implementing them by calling the LiteralControl. Render method. This is generally done to increase the response time of Web applications.
LiteralControl generally does not trigger server events.
You can use the ControlCollection. Add or ControlCollection. Remove methods to Add or Remove text controls from pages or server controls programmatically.
ASP. NET Server controls 3. HtmlControl
The ASP. NET model server component of the HTML element. Each HtmlControl directly corresponds to a specific HTML element, not necessarily an input element ).
ASP. NET Server controls 4. WebControl
Common Web controls. It can be understood as a complex HTML element and a server-side processing logic.
Inheritance relationship:
- System.Object
-
- System.Web.UI.Control
-
- System.Web.UI.TemplateControl
-
- System.Web.UI.Page
-
- System.Web.UI.UserControl
-
- System.Web.UI.LiteralControl
-
- System.Web.UI.HtmlControl
-
- System.Web.UI.WebControl
Generally, users and web controls must be developed by programmers. Xxx
Web Server Components inherited from WebControl often inherit rich UI elements and control capabilities.
User Controls for ASP. NET Server controls
1. Why is it a user control?
Modern people prefer to be lazy, "What you see is what you get", and "drag-and-drop" programming. In an ASP.. NET web projects often have a shared UI in multiple pages, such as header footer. If the content of all pages is consistent, it is usually implemented using a specific js file, however, if the UI parts required for multiple pages are different from those of different user States, dynamic logic processing is required, and common JavaScript/html cannot meet the requirements. Previously, asp was implemented using the include asp file. Now ASP. NET Has Changed various limitations including asp files and uses user controls to solve them.
A user control is essentially an independent ASP. NET file with the extension ascx. User Controls usually depend on specific ASP. NET web projects. ASP. NET page parser dynamically generates a class from the aspx file, compiles it to a specific plug-in temporary cache to host the dll), and according.. net.
2. How to obtain the user control
To obtain the user control, in vs, you only need:
In the web Project, add-> User Control-> enter the user control name-> on the blank page, perform the uidesign and store.
You can drag and drop the user control on a web form to use the user control. In this case, vs replaces us with the following:
Add a register command on the page using the user control. Specifically:
- ﹤%@ Register TagPrefix="uc1" TagName="WebUserControl1" Src="WebUserControl1.ascx" %﹥
The page interpreter can be interpreted as: <uc1: WebUserControl1 is interpreted as a user control, and uc1 is the tag prefix similar to the asp tag prefix of a standard web control ), webUserControl1 serves as the label of this user control. When this combination is encountered, it is interpreted as using the user control instance. The Src value is the virtual path of the user control source file, but cannot be an absolute path.
3. Background of ASP. NET User Controls)
ASP. NET is compiled, and processing user controls is similar to processing pages. All elements on the pages are compiled into specific classes and called and triggered by ASP. NET page classes. User Controls are also reused in this way. When processing user controls, the page framework performs the following steps:
Interpret the ascx file as a Managed class derived from System. Web. UI. UserControl
Dynamically compile to auto-generated accessories.
The above process only occurs when the user control is used for the first time. Subsequent reuse of this user control will omit this step. This class will be referenced when you use the register command on the page. User Controls on the page will become instances of this type. In fact, user controls are also written in ASP. NET class, derived from System. web. UI. userControl class, the use of these classes on the page is like using ASP. NET standard class, in order to be different in that the standard control class can be directly instantiated, and the user control needs to compile similar pages before use, classes can be instantiated after being compiled and assembled into accessories.
4. User Control Programming considerations
User components cannot be instantiated using the new method, because the user control class is dynamically generated. In the new method, this should be the page Compilation Time, and the user control has not been run yet ), the user control class does not exist. However, the Page. LoadControl (string controlname) can be used for loading. In this case, the refence command must be used for loadControl to locate the user control:
- ﹤%@ Refence Control=”xxx/UserControlSamples.ascx”%﹥
User Controls can be nested by other user controls, but must be correctly referenced.
The user control itself belongs to the UI and can be cached. It is determined by the OutPutCache command at the top of the ascx file.
The URL in the user control code refers to the path in which the user control exists, rather than calling the Page code path of the user control. You must use Page. ResolveUrl for correct parsing.
ASP. NET Server controls for ASP. NET Component Design and learning are introduced here. I hope you can learn ASP. NET Server controls for ASP. NET Component Design.
- Analysis on the operation list and template editing during ASP. NET Control Design
- Analysis of ASP. NET control designer
- Introduction to ASP. NET Component Design
- ASP. NET Component Design-Analysis of ASP. NET Timer
- ASP. NET Component Design learning-creating a project library